Angular 2 TypeError:无法读取未定义的属性'toUpperCase'
问题描述:
我正在开发一个医疗网站,当药物的数量为< 50时,我想在medicament.component.HTML的页面上显示警报。 我这样做:Angular 2 TypeError:无法读取未定义的属性'toUpperCase'
<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>
但我不知道为什么它不工作,错误的是:
> 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">
"): [email protected]: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">
"): [email protected]:18
答
在这里你的日志,你可以看到错误的观点:
<span [ERROR ->]*ngIf="{{medicament.quantity}} < 50">
,这是因为你使用一个属性的表达式,你不应该。你只需要使用属性您比较:
<span *ngIf="medicament.quantity < 50">
答
ngIf已经在角度而言,这意味着,你必须删除括号{{}}
在这串你尝试使用toUpperCase?你可以提供你的控制器或任何其他的JS? – Sandwell