1
我正在使用多個服務,我使用內容加載方法。它們每個都顯示自己的loadController來顯示加載窗口。 如何檢測加載窗口已經存在,以防止顯示新的?如何檢測Ionic 2 RC3 Angular 2中的加載窗口?
*注意:我需要檢測它在服務中,但不在組件中。
我正在使用多個服務,我使用內容加載方法。它們每個都顯示自己的loadController來顯示加載窗口。 如何檢測加載窗口已經存在,以防止顯示新的?如何檢測Ionic 2 RC3 Angular 2中的加載窗口?
*注意:我需要檢測它在服務中,但不在組件中。
請看看這段代碼;我使用它的不同的東西,但我想它可以派上用場:
import { Nav, Platform, IonicApp, ... } from 'ionic-angular';
@Component({
selector: 'page-custom',
templateUrl: 'custom.html'
})
export class CustomPage {
constructor(private platform: Platform,
private ionicApp: IonicApp) {
// ...
}
public showModalByClosingPreviousOne(): void {
let activePortal = this.ionicApp._loadingPortal.getActive() ||
this.ionicApp._modalPortal.getActive() ||
this.ionicApp._toastPortal.getActive() ||
this.ionicApp._overlayPortal.getActive();
if (activePortal) {
// Dismiss the active portal
activePortal.dismiss();
activePortal.onDidDismiss(() => {
// Here you can show the new one...
});
return;
}
}
// Or maybe you can just use the `activePortal` property to avoid
// showing another loading instead of closing the previous one.
public showNewModal(): void {
let activePortal = this.ionicApp._loadingPortal.getActive() ||
this.ionicApp._modalPortal.getActive() ||
this.ionicApp._toastPortal.getActive() ||
this.ionicApp._overlayPortal.getActive();
if (!activePortal) {
// Show your modal
}
}
}
這是件好事。但我需要檢測它不在組件中。我需要在我的一個服務課程中檢測它。你有任何解決方案? –
您的服務可以注入ionicapp類,並在那裏檢查。 – misha130
@AlexanderZakusilo從服務中執行與視圖相關的事情(如顯示加載)是非常糟糕的做法。在調用服務之前,您應該檢查是否需要在組件中顯示模式。服務完成後,再次從組件中隱藏加載窗口。 – sebaferreras