AngularJS纳克级过滤器不工作

AngularJS纳克级过滤器不工作

问题描述:

我有我的纳克级的简单过滤器,寻找一个摆脱,随着服务业务的我NG重复“1A”AngularJS纳克级过滤器不工作

ng-class="{'couldBeWrong':rid.indexOf('1A') > -1}" 

如果RID开始始于1A那么类couldBeWrong的应该应用

我也曾尝试各种变化如

class="{'couldBeWrong':rid.indexOf('1A') > -1}" 

ng-class="{'couldBeWrong':service.rid.indexOf('1A') > -1}" 

编辑:基于公认的答案,这里是我的解决方案

加入到控制器

$scope.getClass = function(field){ 
    if(field.indexOf('1L') > -1){ 
     return true;//or you can modify as per your need 
    }else{ 
     return false;//you can modify as per your need 
    } 
} 

,并在重复的NG-CLASS

ng-class="{'couldBeWrong':getClass(service.rid)}" 

试试这个

ng-class="{'couldBeWrong':getClass(rid)}" 

In Controller

$scope.getClass = function(){ 
    if(rid.indexOf('1A') > -1){ 
    return true;//or you can modify as per your need 
    }else{ 
    return false;//you can modify as per your need 
    } 
} 
+0

你忘记关闭括号:NG-CLASS = “{ 'couldBeWrong':的getClass(RID)}” –

+0

耶@VitaliyAndrusishyn因为我不运行它:) –

+0

我根据我的答案在这一点上,只是稍微调整了一下..现在加入到OP – MOLEDesign

你似乎忘记了大括号。它应该是这样的:

ng-class="{'couldBeWrong':rid.indexOf('1A') > -1}" 
+0

对不起坏复制粘贴.. – MOLEDesign

+0

你能提供模板加控制器吗?随着你所提供的,它有望运作 –