[Fixed] Angular 5 Checking the value of a variable on and *ngIf statement

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'".

Leave a Reply

(*) Required, Your email will not be published