Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
9
rated 0 times [  14] [ 5]  / answers: 1 / hits: 46489  / 7 Years ago, mon, april 3, 2017, 12:00:00

While adding a single class works great in this way -



[class.loading-state]=loading



But how do I add multiple classes
Ex if loading is true add class - loading-state & my-class



How do I get it done via the [class] binding


More From » angular

 Answers
26

You can do this by simply using ngClass :



Here first,second and third are the name of the classes.



And instead of true/false , you can directly put your conditions over there



 <div [ngClass]={'first': true, 'second': true, 'third': false}>...</div>


In your case



 <div [ngClass]={'loading-state': loading, 'my-class': loading }>...</div>


Or Shorter Veriosn (as @matko.kvesic commented)



<div [ngClass]={'loading-state my-class': loading}>...</div>

[#58293] Friday, March 31, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
aiyannam

Total Points: 642
Total Questions: 96
Total Answers: 102

Location: Equatorial Guinea
Member since Sun, Feb 14, 2021
3 Years ago
;