2

I have a simple filter on my ng-class that looks for a rid that begins with '1A' in my ng-repeat of service in services

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

If the rid begins with 1A then the class of couldBeWrong should be applied

I have also tried various variations such as

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

and

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

EDIT : Based on accepted answer, here is my solution

Added to controller

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

and the NG-CLASS in the repeat

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

2 Answers 2

2

Try this

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   
  }
}
Sign up to request clarification or add additional context in comments.

3 Comments

Your forget to close brackets: ng-class="{'couldBeWrong':getClass(rid)}"
yeah @VitaliyAndrusishyn because I didnt run it :)
I based my answer on this, just tweaked it a little.. adding to OP now
1

You seem to forget the closing braces. It should be like this:

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

1 Comment

Could you provide the template plus controller. With what you have provided, it is expected to work

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.