2016-11-13 7 views
1

ionic2(v 2.1.7)でモーダルフォームを閉じた後にメソッドを呼び出すにはどうすればよいですか? (これはサービスを更新します)、次の私のワークフローモーダルフォームが閉じるときのコールバック

  • ユーザーは、モーダルフォーム(ページB)を開くためのボタンをクリックしてページ(ページA)
  • をロードしている
  • いくつかの詳細を追加
  • は今、私はこれが義和ある

をページAにコールバックを追加し、 からサービスを新しい値を読みたいモーダルフォーム(ページB)

  • を閉じますトン私は

    #page A 
    let modal = this.modalCtrl.create(NewListPage); 
    modal.present(); 
    getValueFromService() 
    
    #page B 
    updateService() 
    this.viewCtrl.dismiss(); 
    

    は現在、このプログラムは、そのはこのため、そのはgetValueFromService()に行く前に閉鎖するPage Bを待っていない、modal.present();当たったら、ある何が起こるか、新たに更新された値は、一度読み出すことはできませんやったIモーダルフォームを閉じます。

    すべてのヘルプは非常にあなたがこのようonDidDismissdoc)を使用することができます

    歓声

  • 答えて

    1

    をいただければ幸いです:あなたも

    // Page B 
    updateService(); 
    this.viewCtrl.dismiss(); 
    

    をしてください言ったよう

    // Page A 
    presentModal() { 
        let modal = this.modalCtrl.create(NewListPage); 
    
        modal.onDidDismiss(() => { 
        // This is going to be executed when the modal is closed, so 
        // you can read the value from the service here 
        getValueFromService(); 
        }); 
    
        modal.present(); 
    } 
    

    そして、の間でデータを送信できることに注意してくださいとPage B、ので、多分あなたも、(あなただけの前後にデータを送信するためにそれをやっている場合)、ちょうどこのようにデータを送信するサービスの使用を避けることができます。

    // Page A 
    presentModal() { 
        let modal = this.modalCtrl.create(NewListPage); 
    
        modal.onDidDismiss(dataFromModal => { 
        // You can use the data here 
        console.log(dataFromModal.foo); 
        }); 
    
        modal.present(); 
    } 
    

    とページB

    // Page B 
    // Instead of calling the service, you can send the data to the caller 
    let data = { 'foo': 'bar' }; 
    this.viewCtrl.dismiss(data); 
    
    +1

    ありがとうございました。完全に動作します。 – sameera207

    +0

    嬉しいです:) – sebaferreras

    関連する問題