3

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

6

Ionic2/3 is built on top of Angular2/4 (or just Angular) so the correct way to use the click event would be:

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

You can find more information in Angular docs

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.