I have a Modal in Ionic 4. I\'d like to close it, when a user press the back button on her mobile (or the bac
Enol's answer helped me find a solution, thanks for that.
platform.registerBackButtonAction
does no longer exist in v4. I tried platform.backButton.subscribe
instead, but it didn't work. What works is this:
private backbuttonSubscription: Subscription;
constructor(private modalCtrl: ModalController) {
ngOnInit() {
const event = fromEvent(document, 'backbutton');
this.backbuttonSubscription = event.subscribe(async () => {
const modal = await this.modalCtrl.getTop();
if (modal) {
modal.dismiss();
}
});
}
ngOnDestroy() {
this.backbuttonSubscription.unsubscribe();
}