我想在按下按钮时更改按钮的文本,并在再次单击时将其更改回来。我怎样才能做到这一点?
我尝试过类似的东西。但我不知道我可以在文本中找到谁,因为没有像离子按钮的颜色这样的属性
HTML
<button (click)="changeText()" ion-button>Hello</button>
TS
public text: string = 'hello';
构造函数
public changeText(): void {
if(this.text === 'hello') {
this.text = 'rank'
} else {
this.text = 'hello'
}
}
您可以使用插值,然后您的按钮将如下所示:
<button (click)="changeText()" ion-button>{{text}}</button>