Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
38
rated 0 times [  40] [ 2]  / answers: 1 / hits: 19972  / 10 Years ago, wed, july 2, 2014, 12:00:00

How to show a vlaue in angularjs ng-show like



ng-show = role in ['admin', 'user', 'buyer']


need to show a div if role is any of the things in that array.


More From » angularjs

 Answers
37

Use the function indexOf in array to find whether a element is part of the array. It will return the position of the element if found or will return -1.



So you can use an expression like



ng-show = ['admin', 'user', 'buyer'].indexOf(role)!=-1 to show/hide data


[#70349] Monday, June 30, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
davion

Total Points: 458
Total Questions: 109
Total Answers: 100

Location: Taiwan
Member since Mon, Sep 6, 2021
3 Years ago
;