Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 906
Chebbi Ala Eddine Avatar asked Nov 28 '22 00:11

Chebbi Ala Eddine


1 Answers

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

<span *ngIf="medicament.quantity < 50">
like image 194
Sasxa Avatar answered Jan 12 '23 00:01

Sasxa