0

I'm new to Angular and I'm trying to add a class to a table row based on the value of the array it's looping over, as below:

        <tbody>
            <tr ng-repeat="change in changes|filter:query|orderBy:predicate:reverse">
                <td>{{change.Infrastructure_Change_ID}}</td>
                <td  ng-class="{red: '{{change.Executive_Summary}}' === 'Undefined'}">{{change.Executive_Summary}}</td>
            </tr>
        </tbody>

The Executive_Summary contains free text, and it will correctly match 'Undefined' and apply class 'red'. However this text can contains quotes, slashes and all sorts of characters that break angular. I'm sure there is a way of adding class 'red' without all the 'Unterminated quote at column..' I have in my log now.

Any suggestions?

1 Answer 1

1

ngClass accepts an expression so you shouldn't need to worry about escaping quotes.

<td ng-class="{red: (change.Executive_Summary == undefined)}">
  {{change.Executive_Summary}}
</td>

Example on jsfiddle

Sign up to request clarification or add additional context in comments.

1 Comment

What about if I want to apply the class to the tr element itself?

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.