Search code examples
angularjsif-statementng-hide

How check with angular if a value contains a certain value?


I have a value from a remote api that contains a comma separated list. The value is for example "4,6,7" that's displays in the template like this:

<li>{{detail[0].list}}</li>

I want to use ng-hide if the comma separated list contains a number that's in the list. How I check if there is a 6 (for example) in the comma separated list? the idea is:

<li ng-hide="if detail[0].list contains 6">{{detail[0].list}}</li>

Solution

  • Since you seem to have a string seperated by commas you'll need to split it first

    <li ng-hide="detail[0].list.split(',').indexOf(6) > -1">{{detail[0].list}}</li>
    

    This will handle the case of your value being '4,5,66,7' not hiding the element