2017-06-12 133 views
2

我有一個按鈕,我爲onclick屬性定義了doLogout函數,但是每次點擊該按鈕時都會顯示以下錯誤:ionic 3 - 運行時錯誤函數未定義 - ReferenceError:函數未定義在HTMLButtonElement.onclick

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 
    } 

} 

回答

5

Ionic2/3是建立在Angular2的頂部/ 4(或只角),所以要使用正確的方法單擊事件是:

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

你可以找到Angular docs

更多信息
相關問題