簡體   English   中英

禁用android設備后退按鈕,直到ionic LoadingController關閉

[英]Disable android device back button until ionic LoadingController close

我們致力於離子本機移動應用。在應用中有超過10頁。

加載程序代碼:// LoaderService

    this.loader = this.loadingCtrl.create({
          content: "Loading",
          //duration: 2000,
        });
        return this.loader;
this.loader = this.LoaderService();
this.loader.present();//Loader start
his.loader.dismiss();//Loader Stop

加載程序我們使用的是每一頁。如果加載程序在那段時間內打開,則用戶單擊后退按鈕,后退按鈕功能正常工作,它將轉到其他頁面加載程序,也將進入下一頁。

我們需要加載器后退按鈕代碼是否應該停止工作

后退按鈕代碼app.component.ts

if (this.platform.is('android')) {
        this.platform.registerBackButtonAction((e) => {
            //my code
          });
        }

我們嘗試了一種方法,例如當加載器存在時將put標志設置為true。而將disset設置標志設置為false。但是我們無法更改每個頁面。為此給我任何想法

只需定義一個變量即可存儲是否正在加載負載,並在您的服務中包裝存在和關閉函數

LoaderService

loader: any;
isShowLoading: false;
constructor(){
   this.loader = this.loadingCtrl.create({
       content: "Loading",
   });
   this.loader.onDidDismiss(()=>{
        this.isShowLoading = false; //loader dismissed
    })
}

showLoading(){
    this.loader.present();
    this.isShowLoading = true;
}

hideLoading(){
    this.loader.dismiss();
    this.isShowLoading = false;
}

SomeComponent

this.platform.registerBackButtonAction((e) => {
     return !this.loaderService.isShowLoading
}); 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM