How to add and remove class with AngularJS?

前端 未结 2 2003
一个人的身影
一个人的身影 2021-01-12 16:08

I have a few buttons that work like switchers. If you click one it becomes active and \"shuts down\" other buttons. I did this using jQuery but would like to use AngularJS.

2条回答
  •  心在旅途
    2021-01-12 17:13

    You could have ng-click that can toggle selected flag, that could be use with ng-class to bind / unbind class.

    Markup

    
    

    Working Fiddle

    Better way

    You could easily do this by using ng-repeat which will reduce your line of code.

    Markup

    $scope.strengths = ["weak","normal","strong"];
    

    Code

    
    

提交回复
热议问题