Angular ngClass and click event for toggling class

后端 未结 7 1323
粉色の甜心
粉色の甜心 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 19:04

    If you want to toggle text with a toggle button.

    HTMLfile which is using bootstrap:

    <input class="btn" (click)="muteStream()"  type="button"
              [ngClass]="status ? 'btn-success' : 'btn-danger'" 
              [value]="status ? 'unmute' : 'mute'"/>
    

    TS file:

    muteStream() {
       this.status = !this.status;
    }
    
    0 讨论(0)
提交回复
热议问题