0

I want to use multiple class in ng-class.These classes comes from my directive.

I need something like this;

ng-class="item.test1 item.test2"

test1 and test2 are my css classes.

When i call like this ,it does not work.

How can i call multiple class using ng-class?

3 Answers 3

2

You can use array notation for multiple classes:

<my-element ng-class="[item.test1, item.test2]">Classes applied</my-element>

JSFIDDLE

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

1 Comment

by the way if the classes are test1 & test2,one needs to remove the "item.", which I don't understand anyway
1

Or you can simply use class for that purpose:

 <div class="{{item.test1}} {{item.test2}}"></div>

Comments

0

you can also do like this, it's a conditional:

<my-elem ng-class="{'class1':var==value1','class2':var=='value2'}">

but really, that's all in the official document you could have search for it.

1 Comment

The question wasn't about conditional, just to apply multiple classes

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.