Can ngClass use ternary operator in Angular 2?

前端 未结 3 1093
慢半拍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:43

    Yes. What you wrote works:

    Plunker

    The result of the expression on the the right-hand side has to evaluate to one of the following:

    • a string of space-delimited CSS class names (this is what your expression returns)
    • an Array of CSS class names
    • an Object, with CSS class names as keys, and booleans as values

    Maybe you had some other error in your code?

提交回复
热议问题