あなたはIonic docsregisterBackButtonAction
で見ることができるように機能を返します。
、呼び出されたときに、そのバックボタン アクションの登録を解除する関数。
ページを離れるとき、あなたはこのように、デフォルトの動作を復元するために、その機能を使用できるように:あなたが見ることができるように
import { Component} from '@angular/core';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
// Property used to store the callback of the event handler to unsubscribe to it when leaving this page
public unregisterBackButtonAction: any;
constructor(...) { ... }
ionViewDidEnter() {
this.initializeBackButtonCustomHandler();
}
ionViewWillLeave() {
// Unregister the custom back button action for this page
this.unregisterBackButtonAction && this.unregisterBackButtonAction();
}
public initializeBackButtonCustomHandler(): void {
this.unregisterBackButtonAction = this.platform.registerBackButtonAction(() => {
this.customHandleBackButton();
}, 10);
}
private customHandleBackButton(): void {
// do what you need to do here ...
}
}
、キーはregisterBackButtonAction
メソッドのコールバックを格納することで、後でページを終了するときに使用します(またはデフォルトの動作を復元する場合)。
this.unregisterBackButtonAction = this.platform.registerBackButtonAction(() => {
this.customHandleBackButton();
}, 10);
ありがとう!私はイベントリスナーのための順序ハンドラのように何らかの形でそれを格納することについて考えましたが、私はそれらを登録解除する方法を知らずに残しました。 –
それは助けてくれたことを聞いてうれしいです:) – sebaferreras
同じ文字のTypeScriptのバージョンを見ることが大好きです –