0

I would like to use a scope variable and and set css dynamically within html.

<div ng-class="myClassScope, { 'dynamic-class': !ifIsNot }">
2
  • Do you have a question? Commented Aug 15, 2014 at 13:27
  • 1
    I think I asked it. this does not work. Commented Aug 15, 2014 at 13:54

2 Answers 2

2

It your myClassScope is intended to always be applied, use ng-class this way:

<div class="myClassScope" ng-class="{'dynamic-class': !ifIsNot }">
Sign up to request clarification or add additional context in comments.

Comments

2

Is this what you want?

<div ng-class="{ 'dynamic-class': !myClassScope }">

EDIT:

If you want to use multiple ng-class directives, it won't work. See this fiddle

In order to use two ng-class directives, you can nest the elements, or you can bind to the class attribute:

<div ng-class="test_one">
    <div ng-class="{ 'test_two': !test_two }">test_two</div>
</div>
<div class="{{test_one}}" ng-class="{ 'test_two': !test_two }">test_three</div>

4 Comments

no, myClassScope is in ctrl, scope.myClassScope = 'custom-class'
so you are trying to use both the boolean ng-class object and the class string? see my edit
class={{ test_one }} this really slows down the app
For me appying multiple classes works like so: <... ng-class="{'class1': scopeVarForClass1, 'class2': scopeVarForClass2}" ... >

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.