Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

173
Vistas
In which part of the code should I check for undefined

There is a method

product$!: Observable<Product>;

  getProduct(): void {
    this.product$ = this.route.params
      .pipe( switchMap( params => {
        return this.productServ.getById(params['id'])
      }))
  }

which returns, an object of type

export interface Product {
  type?: string
  id?: string
  title?: string
  date?: Date | undefined;
}

and a template that displays the properties of this object

<div *ngIf="product$ | async as product; else loading">
  <h2>{{ product.title}}</h2>

As a result of calling the (getProduct) method, the variable this.product$ may be undefined. Therefore, IDEA throws an error in this line of the template

<h2>{{ product.title}}</h2>

How is this problem solved correctly

  • in the template, add a check *gif="product.title"
  • or this problem should be solved in the code, then the question is how to do it correctly
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Did you try *ngIf="(product$ | async) as product; else loading"?

Also you can define an empty observable as product$ = Observable.of<Product>(Product()) before rendering

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda