Can ngClass use ternary operator in Angular 2?

前端 未结 3 1096
慢半拍i
慢半拍i 2021-02-02 05:31

In Angular 1, the code below works well.

But when I try to do simi

3条回答
  •  执念已碎
    2021-02-02 05:56

    You can try the followings.....

    For ternary operator use:

    [ngClass]="condition1==condition2?'class-1':'class-2'"
    

    For multiple condition use:

    [ngClass]="{'class-1':condition1==condition2, 'class-2': condition3==condition4}"
    

    thnks...

提交回复
热议问题