angularjs - Difficulty adding multiple classes wit ng-class -
i'm trying add 2 classes div using ng-class, though checkforactive returning true, it's being ignored , class_{{$index}} getting added.
if remove class_{{$index}} altogether, active added correctly.
is there obvious mistake in syntax here?
<div "ng-class="{active: checkforactive, disabled: checkfordisable, class_{{$index}}} "></div>
you provide true value key class_{{$index}} property gets added class name class list of element. way active: checkforactive.
i.e
{active: checkforactive, disabled: checkfordisable, class_{{$index}} :true} but believe there undesired behavior due usage of interpolation ({{) within ng-class directive (atleast used happen older versions). use array.
ng-class="[checkforactive && 'active' , checkfordisable && 'disabled', 'class_' + $index]" the above method add class name false if active or disabled false, should harmless.
or pass index controller function getstatus($index) , return object there , use in ng-class directive.
$scope.getclass = function(){ var obj = {active: $scope.checkforactive, disabled: $scope.checkfordisable}; obj['class_' + this.$index] = true; return obj; } and
ng-class="getclass()" @okazari pointed out indeed works mixing class ng-class do:
class="class_{{$index}}" ng-class="{active: checkforactive, disabled: checkfordisable}"
Comments
Post a Comment