0

我正在ng-class使用它分配给一个元素。

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

但它给了我很多错误。它的语法有什么问题?这样做的正确方法是什么?

4

2 回答 2

2

利用

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

于 2014-02-12T12:31:20.817 回答
1

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>
于 2014-02-12T12:22:15.357 回答