如何在点击事件中更改按钮的文本?

问题描述 投票:-2回答:1

我想在按下按钮时更改按钮的文本,并在再次单击时将其更改回来。我怎样才能做到这一点?

我尝试过类似的东西。但我不知道我可以在文本中找到谁,因为没有像离子按钮的颜色这样的属性

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'
      }
    }
angular typescript ionic3
1个回答
2
投票

您可以使用插值,然后您的按钮将如下所示:

<button (click)="changeText()" ion-button>{{text}}</button> 
© www.soinside.com 2019 - 2024. All rights reserved.