【问题标题】:Update view and value in ionic 2更新 ionic 2 中的视图和值
【发布时间】:2016-10-26 16:37:12
【问题描述】:

您好,我刚开始在我的项目中使用 ionic 2,如何更新 ionic 2 中的 ui 值?只是当我们单击按钮时,一些文本发生了变化。我试过了,但没有用

home.ts

@Component({
  templateUrl: 'build/pages/home/home.html'
})

export class HomePage {
  public test: any;
  constructor(private nav: NavController) {
  }

  update(){
    this.test = "updated text";
  }
}

home.html

<ion-content>
    <p>{{test}}</p>
    <button (click)="update()">update</button>
</ion-content>

请帮忙,谢谢!

【问题讨论】:

    标签: ionic-framework angular ionic2


    【解决方案1】:

    在 HTML 上,您应该在修改 test 变量值时使用 {{test}}

    <ion-content>
        <p>{{test}}</p>
        <button (click)="update()">update</button>
    </ion-content>
    

    可能性是,你可能错过了bootstrap你的应用程序主要组件,你可以看到类似的answer here

    【讨论】:

    • 对不起,只是错字.. 是的,已经使用测试作为变量,但仍然没有工作。有什么想法吗?
    • @BijakAntusiasSufi 您可能错过了引导您的应用程序组件。看看更新的答案,谢谢:)
    • 嗨,谢谢你的回答。这是 angular 2,但我不知道将其应用于 ionic 2
    • @Component改成@Page/@App
    【解决方案2】:

    将您的 home.html 更改为此

    <ion-content>
    <p>[(ngModel)]="test"</p>
    <button (click)="update()">update</button>
    

    【讨论】:

      猜你喜欢
      • 2016-07-10
      • 1970-01-01
      • 2018-03-21
      • 1970-01-01
      • 2017-01-24
      • 1970-01-01
      • 2016-05-14
      • 2017-05-07
      • 1970-01-01
      相关资源
      最近更新 更多