Angular ngClass and click event for toggling class

后端 未结 7 1342
粉色の甜心
粉色の甜心 2020-12-02 18:30

In Angular, I would like to use ngClass and click event to toggle class. I looked through online but some are angular1 and there isn\'t any clear instruction or

7条回答
  •  甜味超标
    2020-12-02 18:48

    Instead of having to create a function in the ts file you can toggle a variable from the template itself. You can then use the variable to apply a specific class to the element. Like so-

    Some content

    So when status is true the class success is applied. When it is false danger class is applied.

    This will work without any additional code in the ts file.

提交回复
热议问题