Question

I am assigning ng-class to an element using this.

ng-class="{'level-' + {{row.level}}:true,active:TestFlag==true}"

but it is giving me tons of errors. What is wrong with its syntax? What is the correct way of doing this?

Was it helpful?

Solution

use

ng-class="{'level-{{row.level}}': true, active: TestFlag==true}"

OTHER TIPS

I think you'll need to pull the first part off and do it like this:

ng-class="{active:TestFlag}" class="{{'level-' + row.level}}"

Demo: http://plnkr.co/edit/NSZbm1sntT3uwDgx4g0L?p=preview

You can also build an object in your controller:

$scope.classSet = {};
$scope.classSet['level-' + $scope.row.level] = true;
$scope.classSet['active'] = $scope.TestFlag;

 <p ng-class="classSet">Here</p>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top