如何在Ionic 2 RC3 Angular 2中检测负载窗口?

时间:2016-12-09 12:31:54

标签: angular typescript ionic2

我使用多种服务,我使用内容加载方法。每个都显示自己的loadController来显示加载窗口。 如何检测加载窗口已经存在,以防止显示它的新内容?

*注意:我需要在服务中检测它,但不在组件中检测它。

1 个答案:

答案 0 :(得分:1)

Please take a look at this piece of code; I use it for something different, but I guess it may come in handy:

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
        }
    }

}