2016-12-09 6 views
1

私はコンテンツメソッドのロードを使用するいくつかのサービスを使用しています。それぞれに独自のloadControllerが表示され、ロードウィンドウが表示されます。 どのように負荷ウィンドウを検出するには、それが新しいのを防ぐために存在するのですか?イオン2の負荷ウィンドウを検出する方法RC3角度2?

*注:サービスでは検出する必要がありますが、コンポーネントでは検出できません。

答えて

1

このコードをご覧ください。私は別の何かのためにそれを使用しますが、それは便利かもしれないと思います:

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

} 
+1

良いです。しかし、私はそれをコンポーネントではなく検出する必要があります。私は私のサービスクラスの1つでそれを検出する必要があります。何か解決策はありますか? –

+0

あなたのサービスは、ionicappクラスを注入してチェックすることもできます。 – misha130

+0

@AlexanderZakusiloサービスからビューに関連すること(ローディングを表示するなど)を行うことは非常に悪いことです。サービスを呼び出す前に、コンポーネントからモーダルを表示する必要があるかどうかを確認する必要があります。サービスが終了すると、コンポーネントから読み込みウィンドウが再び非表示になります。 – sebaferreras

関連する問題