ionic 3 - 运行时错误函数未定义 - ReferenceError:函数未定义在HTMLButtonElement.onclick
问题描述:
我有一个按钮,我为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
}
}
答
Ionic2/3是建立在Angular2的顶部/ 4(或只角),所以要使用正确的方法单击事件是:
<button ion-button block (click)="doLogout()">Logout</button>
你可以找到Angular docs
更多信息