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

160
Vistas
Angular 2 TypeError: Cannot read property 'toUpperCase' of undefined

I am developing a medical website , i want show alert in page of medicament.component.HTML when the quantity of medicaments is < 50 . I did this :

 <span *ngFor="let medicament of medicaments" >
        <span *ngIf="{{medicament.quantity}} < 50">
             <div class="callout callout-danger lead">
          <h4>Alert!</h4>
          <p>Vous devez charger le stock de medicaments {{medicament.nom}}                         
  de type {{medicament.type}}  </p>
        </div>
        </span></span>

But i don't know why it doesn't work , the error is :

       > Unhandled Promise rejection: Template parse errors:
        TypeError: Cannot read property 'toUpperCase' of undefined ("<span              
       *ngIf="medicaments">
    <span *ngFor="let medicament of medicaments" >
        <span [ERROR ->]*ngIf="{{medicament.quantity}} < 50">
             <div class="callout callout-danger lead">
       "): MedicamentComponent@26:18
     Can't bind to '*ngIf' since it isn't a known property of 'span'.             
     ("<span *ngIf="medicaments">
    <span *ngFor="let medicament of medicaments" >
        <span [ERROR ->]*ngIf="{{medicament.quantity}} < 50">
             <div class="callout callout-danger lead">
      "): MedicamentComponent@26:18
about 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

You shouldn't use interpolation {{ }} in ngIf; it expects an expression:

<span *ngIf="medicament.quantity < 50">
about 4 years ago · Santiago Trujillo Denunciar

0

ngIf is already in the angular context, which means, that you must remove the brackets {{}}

about 4 years ago · Santiago Trujillo Denunciar

0

Here in your logs you can see the point of error:

 <span [ERROR ->]*ngIf="{{medicament.quantity}} < 50">

and it is because you are using an expression on a property where you shouldn't. You just need to use property you are comparing:

 <span *ngIf="medicament.quantity < 50">
about 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