Aka*_*ary 2 button back ionic-framework ionic2 ionic3
我想知道当我们在 ionic 3 中默认单击 ion-navbar 后退按钮时调用哪个函数。我想在硬件后退按钮单击时调用相同的函数。
您可以使用 registerBackButtonAction的平台服务。您可以在app.component.ts 中覆盖硬件后退按钮操作,如下所示。记得拨打registerBackButtonAction后Platform.ready()。
import { Platform, App } from 'ionic-angular';
@Component({
templateUrl: 'app.html'
})
export class MyApp {
constructor(public platform: Platform, private app: App) {
this.platform.ready().then(() => {
this.platform.registerBackButtonAction(() => {
let nav = this.app.getActiveNav()
if (nav.canGoBack()) {
// If there are pages in navigation stack go one page back
// You can change this according to your requirement
nav.pop();
} else {
// If there are no pages in navigation stack you can show a message to app user
console.log("You cannot go back");
// Or else you can exit from the app
this.platform.exitApp();
}
});
});
}
}
Run Code Online (Sandbox Code Playgroud)
希望这会帮助你。
| 归档时间: |
|
| 查看次数: |
1422 次 |
| 最近记录: |