【问题标题】:ionic 3 - Runtime Error function not defined - ReferenceError: function is not defined at HTMLButtonElement.onclickionic 3 - 未定义运行时错误函数 - ReferenceError:函数未在 HTMLButtonElement.onclick 中定义
【发布时间】:2017-11-14 05:53:31
【问题描述】:

我有一个按钮,我为该按钮定义了 onclick 属性的 doLogout 函数,但每次单击该按钮时都会显示以下错误:

Runtime Error function not defined - ReferenceError: function is not defined at HTMLButtonElement.onclick

代码很简单,我在其他页面用过,函数调用正确。这是我的 HTML 文件:

<ion-header>  
  <ion-navbar>
    <ion-title>Logout</ion-title>
  </ion-navbar>
</ion-header>

<ion-content>
  <div padding>
  <button ion-button block onclick="doLogout()">Logout</button>
 </div>  
   </ion-content>

这是 ts 文件:

export class LogoutPage {

  constructor(public navCtrl: NavController, public navParams: NavParams,
  public api : Api) {
  }


  doLogout(){
       //does something
  }

}

【问题讨论】:

    标签: html angular typescript ionic2 ionic3


    【解决方案1】:

    Ionic2/3 建立在 Angular2/4(或只是 Angular)之上,因此使用点击事件的正确方法是:

    <button ion-button block (click)="doLogout()">Logout</button>
    

    您可以在Angular docs找到更多信息

    【讨论】:

      猜你喜欢
      • 2017-05-22
      • 2019-11-30
      • 2014-11-24
      • 2023-03-13
      • 1970-01-01
      • 2018-08-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多