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

时间:2017-06-12 16:53:12

标签: html angular typescript ionic2 ionic3

I have a button for which I defined a doLogout function for the onclick property, but everytime I click on that button the following error is shown:

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

The code is very simple, and I used it in other pages, where the function is called correctly. This is my HTML file:

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

And this is the ts file:

export class LogoutPage {

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


  doLogout(){
       //does something
  }

}

1 个答案:

答案 0 :(得分:6)

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

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

您可以在Angular docs

中找到更多信息