Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ng-show based on a value present in an array

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.

like image 521
Govan Avatar asked Jul 02 '14 07:07

Govan


1 Answers

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

like image 72
guru Avatar answered Oct 02 '22 10:10

guru