문제

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?

도움이 되었습니까?

해결책

use

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

다른 팁

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>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top