我正在使用 Angular 5,并且正在尝试检查组件的 html 模板中的变量值。
所以它看起来像这样:
<div *ngIf="item='somevalue'">
我收到此错误:
ht 错误:模板解析错误:
Parser Error: Bindings cannot contain assignments at column 17 in...
这不能用角度来完成吗?
原文由 user8770372 发布,翻译遵循 CC BY-SA 4.0 许可协议
我正在使用 Angular 5,并且正在尝试检查组件的 html 模板中的变量值。
所以它看起来像这样:
<div *ngIf="item='somevalue'">
我收到此错误:
ht 错误:模板解析错误:
Parser Error: Bindings cannot contain assignments at column 17 in...
这不能用角度来完成吗?
原文由 user8770372 发布,翻译遵循 CC BY-SA 4.0 许可协议
您正在使用单个 = 运算符进行分配。
使用双等于 == 运算符来检查相等或更好地使用 === 来检查严格相等。
<div *ngIf="item === 'somevalue'">
原文由 Gourav Pokharkar 发布,翻译遵循 CC BY-SA 3.0 许可协议
*ngIf 像这样工作
*ngIf="expression"
其中expression
被简单的 Javascript 语句替换,该语句返回boolean
。 But you use one=
and it means that you assign thesomeValue
to theitem
property and if the value is not falsy it will return youtrue
.在您的情况下,您需要编写
*ngIf="item === 'somevalue'"
。