如何在ng-class中添加条件和功能

时间:2015-10-30 13:27:20

标签: angularjs

<!--<li ng-class="{active: aba == 1,  disabled: autenticarAcessoAba(1) }">-->

 <li ng-class="{'active': aba =='2'  , disabled: autenticarAcessoAba(2) && !aba=='2' }">

  $scope.autenticarAcessoAba = function(aba){
        return aba > $scope.ultimaAba;//setar disabled como class

}

我是对手&#39; aba&#39;,有效并禁用其他人&#39; aba&#39;

2 个答案:

答案 0 :(得分:0)

你可以用这个

ng-class="{'active': condition,disabled: functionWhichDecidesTruthyOrFalse(1)}"

答案 1 :(得分:0)

该函数应返回truefalse并将其添加到ngClass表达式

<li ng-class="{active: aba == 1 && !myFunc(1), disabled: myFunc(1)}">

$scope.myFunc= function(aba){
   return aba > $scope.ultimaAba;
}