如何在点击事件中更改按钮的文字? [英] How can I change the button‘s text on a click event?

查看:66
本文介绍了如何在点击事件中更改按钮的文字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在单击按钮时更改按钮的文本,并在再次单击时将其更改回.我该怎么办?

I want to change the text of a button when it‘s cklicked and change it back when it‘s clicked again. How can I do that?

我尝试过类似的方法.但是我不知道该给谁找文字,因为没有像离子按钮那样带有颜色的属性

I tried something like that. But I dont know who I can adress to the text because there is no property like eg with color for ion-buttons

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'
      }
    }

推荐答案

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

You can use interpolation, then your button would look like this:

<button (click)="changeText()" ion-button>{{text}}</button> 

这篇关于如何在点击事件中更改按钮的文字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆