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 in angular?
*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'"
.
You are making assignment instead of comparison
<div *ngIf="item==='somevalue'">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With