Angular2 - Add class to item on click

后端 未结 5 417
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-01 17:18

I have a bunch of list items and would like to highlight each one once it\'s clicked. This is easy for me to do in jQuery or even JavaScript but I\'m lost when it comes to Angul

5条回答
  •  逝去的感伤
    2021-02-01 17:59

    You need to make an array in your class to store highlight status of an item:

    hightlightStatus: Array = [];
    

    Declare local variable in the template associated with ngFor:

    • {{item}}

提交回复
热议问题