AngularJS ng-class 过滤器不工作

AngularJS ng-class filter not working

我的 ng-class 上有一个简单的过滤器,它在我的 ng-repeat of services

中查找以“1A”开头的删除
ng-class="{'couldBeWrong':rid.indexOf('1A') > -1}"

如果 rid 以 1A 开头,则应应用 couldBeWrong 的 class

我也尝试过各种变体,例如

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)}"

在控制器中

$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   
  }
}

你好像忘记了右大括号。应该是这样的:

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