- Forums
- Angular
- How To Apply Class To A Tag In Angular 2
this page will show you an example how you can use to apply a class with a conditional operator [4638], Last Updated: Mon Jun 24, 2024
Angular2
Tue Jan 31, 2017
0 Comments
425 Visits
[class.selected]="string=== AnotherString"
EXAMPLE <li [class.selected]="hero === selectedHero"> foo </li>the code above is saying:
apply the class selected if the hero string is equals to the selectedHero string
in angular 1, you would use it like this:
ng-class="{ 'QuizImageChecked' : answerCheck[0]==option }"or
data-ng-class="{ 'QuizImageChecked' : answerCheck[0]==option }"