Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2 ngClass both array and object syntax together?

In angular 1.x, I can use a combination of the array and object syntax in the same statement, like this:

<div ng-class="[classNameFromController, {'show' : booleanFromController}]"></div>

The same does not work in Angular 2 with the same approach:

<div [ngClass]="[classNameFromController, {'show' : booleanFromController}]"></div>

I can't find anything that suggests it can be done.

What gives?

Cheers!

like image 630
Steve D Avatar asked Dec 09 '16 13:12

Steve D


People also ask

Can we use two NgClass in Angular?

Angular's NgClass Directive So far we've looked at adding just single classes, which is something the NgClass directive can also help us with as it supports multiple classes. Using multiple classes is the real reason to use the NgClass directive. You can think of NgClass as being able to specify multiple [class.

Can we use NGIF and NgClass together?

javascript - ng-if and ng-class-even/odd doesn't work well together and won't get expected outout - Stack Overflow. Stack Overflow for Teams – Start collaborating and sharing organizational knowledge.


1 Answers

From the docs:

<some-element [ngClass]="stringExp|arrayExp|objExp">

which means one of stringExp|arrayExp|objExp (but not two of ;-) )

like image 76
Günter Zöchbauer Avatar answered Nov 07 '22 13:11

Günter Zöchbauer