How to use a $ scope variable within ng-class

1

I have the following code:

<a ng-class="{'text-{{color}}-6': menu == '#background'}" href="#background">
   My Menu
</a:

It works, at first it adds the text-red-6 class to the element. But when I change the color of $scope , ng-class does not change the class.

    
asked by anonymous 04.10.2016 / 14:49

2 answers

2

I've been using ternary operator in in the class attribute:

class="{{menu == '#background' ? 'text-' + color + '-6' : ''}}"
    
04.10.2016 / 15:02
0

Try this:

<div ng-class="{'{{class}}': menu == '#background'}">

...

$scope.color = 'red';
$scope.class = 'text-' + color + '-6';
    
04.10.2016 / 15:15