angularjs - ng-class with multiple options -


i'm fetching data using rest api , 1 of attributes returned can of 3 options;

the options are; negative, warning, success.

i want set class using ng-class based on value returned;

i'm able one; code below;

<div class="alert" ng-class="restaurantnotice(restaurant[0].notice)" ng-if="restaurant[0].notice.length">     <div class="alert-inner inner-large" ng-bind="restaurant[0].notice"></div> </div>  $scope.restaurantnotice = function(a) {     return (a = negative) ? 'negative' : ''; }; 

as can see, if a = negative class negative applied else nothing applied.

now want check 3 options , apply 3 different classes respectively

you can try

<div class="alert" ng-class="{'negative' : restaurant[0].notice.length, 'warning' : restaurant[1].notice.length, 'success' : restaurant[2].notice.length}">     <div class="alert-inner inner-large" ng-bind="restaurant[0].notice"></div> </div> 

duplicate of adding multiple class using ng-class


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -