Change button color after click in Angularjs

前端 未结 3 1065
梦如初夏
梦如初夏 2021-01-20 16:39

This is what I have now: index.html

Todo

3条回答
  •  星月不相逢
    2021-01-20 17:22

    you can use ng-class Define a var like $scope.started = false; and inside you start function set it to true. On your button do this:

    ng-class="{'btn-warning': started, 'btn-danger': !started}"

    another way to write it:

    ng-class="started && 'btn-warning' || !started && 'btn-danger'"

    note: remove btn-danger from your curre class attribute

    EDIT

    The newer, more common way is the standard ternary operator (also easier to read):

    ng-class="started ? 'btn-warning' : 'btn-danger'"

提交回复
热议问题