Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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

<div ng-class="myClassScope, { 'dynamic-class': !ifIsNot }">
share|improve this question
    
Do you have a question? –  Shomz 2 days ago
    
I think I asked it. this does not work. –  Matjaž Jurečič 2 days ago

2 Answers 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>
share|improve this answer
    
no, myClassScope is in ctrl, scope.myClassScope = 'custom-class' –  Matjaž Jurečič 2 days ago
    
so you are trying to use both the boolean ng-class object and the class string? see my edit –  mobabur94 2 days ago
    
class={{ test_one }} this really slows down the app –  Matjaž Jurečič 2 days ago

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

<div class="myClassScope" ng-class="{'dynamic-class': !ifIsNot }">
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.