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
Post a Comment