3
votes

I have a ngClass condition like this :

<div [ngClass]="{'alert alert-danger': alert.type == 0,'alert alert-success': alert.type == 1}"

If alert.type == 1, my class is alert alert-succes, but if alert.type = 0 my class is alert-danger. Why class alert is not here ?

1
I put your code in a quick plnkr - Raven
@Raven Nope, it doesnt work. Inspect the element when it's red, your will only have alert-danger.... - Alex Caron

1 Answers

5
votes

Yes, it seems to be an issue, but It isn't, read a comment for explanation. But you can easily have workaround by taking common class out in class attribute itself.

<div class="alert" 
  [ngClass]="{'alert-danger': alert.type == 0, 'alert-success': alert.type == 1}"

Demo Plunker