puppeteer701
puppeteer701

Reputation: 1285

Use scope variable and dynamic css in ngClass

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

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

Upvotes: 0

Views: 3338

Answers (2)

mobabur94
mobabur94

Reputation: 370

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>

Upvotes: 2

Fedaykin
Fedaykin

Reputation: 4552

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

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

Upvotes: 2

Related Questions