简体   繁体   中英

Toggle text of button with ngClass in Angular

How would I change the text of a toggled class of a button in Angular, so far I have the following to toggle the class, I am using Bootstrap:

html

<!-- toggle button --> 
<button type="button" class="btn btn-primary mt-3 ml-3" (click)="status=!status;" [ngClass]="status ? 'btn-info' : 'btn-primary'"  [disabled]="clicked">Primary</button>
<!-- toggle button --> 

Any idea's?

Your code for ngClass is wrong and i corrected this,

Also if you want to change the text of button you can do it like this :

    <button type="button" class="btn btn-primary mt-3 ml-3" (click)="status=!status;" [ngClass]="{'btn-info' : status, 'btn-primary' : !status}"  [disabled]="clicked">{{status ? 'Info' : 'Primary'}}</button>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM