user2924127 user2924127 - 1 year ago 50
Javascript Question

Hide item that is part of a loop based on a condition

<ul *ngFor="#item of items; #i=index" >
<li [hidden]="{{ item.myattr === 'some_value' }}"> {{ item.val}} </li>


I have the following code shown above. I want hide the list if the item has a value equal some value. In this case I have the items, they have an attribute called
, and if it is equal to
then the item should be hidden. The code I provided though does not work.

Answer Source

You don't need to use interpolation {{}} with property binding [] (actually, you can't):

<li [hidden]="item.myattr === 'some_value'">

Also, read Mistake #1: Binding to the native "hidden" property in

So a better solution is likely

<li *ngIf="item.myattr !== 'some_value'">