【发布时间】:2019-12-16 04:10:58
【问题描述】:
我正在尝试通过后退按钮关闭我的应用 我在github中找到了这段代码
//Called when view is loaded as ionViewDidLoad() removed from Ionic v4
ngOnInit(){
this.initializeBackButtonCustomHandler();
}
//Called when view is left
ionViewWillLeave() {
// Unregister the custom back button action for this page
this.unsubscribeBackEvent && this.unsubscribeBackEvent();
}
initializeBackButtonCustomHandler(): void {
this.unsubscribeBackEvent = this.platform.backButton.subscribeWithPriority(999999, () => {
alert("back pressed home" + this.constructor.name);
});
/* here priority 101 will be greater then 100
if we have registerBackButtonAction in app.component.ts */
}
它有效,但在所有页面上
我只想在主页上限制它
我用了this.constructor.name == HomePage,但也没有用
【问题讨论】:
标签: cordova ionic-framework ionic4