KingJulian
KingJulian

Reputation: 973

Angular apply dynamic class to DOM element when one already exists

I have an element:

<div class="wrapper" > ... </div>

I know I can use angular to apply a class conditionally:

<div ng-class="{'wrapper-big': style.big}" > ... </div>

But I want to keep a static class and add 'big' using angular. Desired output:

<div class="wrapper big" > ... </div>

So the class big is what I want to conditionally add.

Upvotes: 0

Views: 128

Answers (2)

Polochon
Polochon

Reputation: 2219

you can use the class and ng-class attributes together.

<div class="wrapper" ng-class="{'big': /*CONDITION*/}" > ... </div>

Upvotes: 1

Rabi
Rabi

Reputation: 2220

use the array syntax of ng-class.

e.g.
<div ng-class="[style1, style2, style3]" > ... </div>

Here is an example - https://docs.angularjs.org/api/ng/directive/ngClass

Upvotes: 0

Related Questions