【发布时间】:2017-02-24 12:31:12
【问题描述】:
我在我的 ng-class 上有一个简单的过滤器,它在我的服务中的 ng-repeat 中寻找以“1A”开头的摆脱
ng-class="{'couldBeWrong':rid.indexOf('1A') > -1}"
如果 rid 以 1A 开头,则应应用 canBeWrong 类
我也尝试过各种变体,例如
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)}"
【问题讨论】:
标签: javascript angularjs filter ng-class