Issue
I am using angular 5 and I’m trying to check the value of a variable in the html template of the component.
So it looks something like this:
<div *ngIf="item='somevalue'">
I’m getting this error:
ht Error: Template parse errors:
Parser Error: Bindings cannot contain assignments at column 17 in...
Can’t this be done on angular?
Solution
*ngIf work like this *ngIf="expression"
where the expression
is replaces with the simple Javascript statement which returns boolean
. But you use one =
and it means that you assign the someValue
to the item
property and if the value is not falsy it will return you true
.
In your case you need to write *ngIf="item === 'somevalue'"
.