Angular 角度2类型错误:无法读取属性';toUpperCase';未定义的

Angular 角度2类型错误:无法读取属性';toUpperCase';未定义的,angular,typescript,jhipster,Angular,Typescript,Jhipster,我正在开发一个医疗网站,我想在药剂量未处理的承诺拒绝:模板分析错误: TypeError:无法读取未定义(“”)的属性“toUpperCase” ]*ngIf=“{{medicament.quantity}}} "): MedicamentComponent@26:18 无法绑定到“*ngIf”,因为它不是“span”的已知属性。 (" ]*ngIf=“{{medicament.quantity}}} "): MedicamentComponent@26:18 您不应该在ngIf中使用插值{{}

我正在开发一个医疗网站,我想在药剂量<50时在medicament.component.HTML页面显示警报。 我这样做:

 <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>

警觉的!
您是否有药品库存{{medicament.nom}
de类型{{medicament.type}

但我不知道为什么它不起作用,错误是:

       > 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
>未处理的承诺拒绝:模板分析错误:
TypeError:无法读取未定义(“”)的属性“toUpperCase”
]*ngIf=“{{medicament.quantity}}}<50”>
"): MedicamentComponent@26:18
无法绑定到“*ngIf”,因为它不是“span”的已知属性。
("
]*ngIf=“{{medicament.quantity}}}<50”>
"): MedicamentComponent@26:18

您不应该在ngIf中使用插值
{{}
;它需要一个表达式:

<span *ngIf="medicament.quantity < 50">

在您的日志中,您可以看到错误点:

 <span [ERROR ->]*ngIf="{{medicament.quantity}} < 50">
]*ngIf=“{{medicament.quantity}}<50”>
这是因为你在一个不应该使用的属性上使用了一个表达式。您只需使用正在比较的属性:

 <span *ngIf="medicament.quantity < 50">

ngIf已经在角度上下文中,这意味着您必须删除括号{{}


您尝试在哪个字符串上使用toUpperCase?你能提供你的控制器或任何其他JS吗?但是,为什么toUpperCase会出现呢。你调查过吗?