0

I have a directive whose structure is:

<mydir ng-class="i.labels", ng-class="{'elSelected': i.id == selectedId}"></mydir>

Here i.labels is a an array of CSS class names and i.id and selectedId are numbers, all of which are declared inside the controller. I want to apply all the classes contained in the array i.labels and conditionally apply elSelected to mydir. How can I do this with ng-class?

1 Answer 1

1

You can use ng-class to apply array of classes and use class attribute to apply a class conditionally:

<mydir ng-class="i.labels" 
class="{{i.id == selectedId? 'elSelected' : ''}}"></mydir>

Fiddle

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

Comments

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.