Angular - How to apply [ngStyle] conditions

后端 未结 4 959
孤街浪徒
孤街浪徒 2021-02-01 01:00

I have a div that I want to style based on a condition.

If styleOne is true I want a background colour of red. If StyleTwo is true, I want the background colour to be blu

4条回答
  •  悲哀的现实
    2021-02-01 01:53

    For a single style attribute, you can use the following syntax:

    I assumed that the background color should not be set if neither style1 nor style2 is true.


    Since the question title mentions ngStyle, here is the equivalent syntax with that directive:

提交回复
热议问题