2017-10-11 2 views
1

私が経験しています問題が説明するのは少し難しいですが、私は間違っているの約束(角)になっかもしれませんが、それでも...

は私がきれいに次のような状況に対処しようとしています。 一般的には、角度dialogServiceconfirmメソッドを提供したいとします。これは、yesボタンをクリックして確定した約束を返します。これは、確認が実際に成功したときを意味します。しかし、内部のasync操作(これはyes確認で実行される)が完了するまで、ダイアログは開いたままにしておきたい。それが正常に終了したら、ダイアログは閉じなければなりません。

(完全に)このように見ていることになるコードで

外コード:

dialogService.confirm('title', 'message').then => 
     return myLongLastingOperationReturningPromise() 

confirmメソッドの実装このような何か:他の言葉で

def = $q.defer() 

    dialog = ngDialog.open(...) 
    // closePromise or any other custom local promise 
    dialog.closePromise.then => 
     // this is fake, but how can I achieve this? 
     result = def.resolve('closeRequest'); 
     if(typeof result.then == 'function') { 
      result.then => 
       // continue closing the dialog 
     } else if (result === false) { 
      // just do nothing 
     } else { 
      // closing the dialog 
     } 

resolveを呼び出した後の約束チェーンの最後のthenメソッドの結果を取得する方法はありますか?

答えて

0

APIが正常に返されたら、確認を実行する必要があります。

あなたはこの答えをチェックして、

modalInstance = ngDialog.openConfirm({ 
        template: 'xxx.tpl.html', 
        scope: $scope, 
        controller: 'xxxCtrl' 
        }); 

modalInstance.then(function (data) { 
    //This data is returned from confirm 
}); 
+0

こんにちは:呼び出し側で

//$scope is the ngDialog scope here $scope.YesHandler = function() { myLongLastingOperationReturningPromise().then(function(data) { //Execute confirm method after API returned $scope.confirm(data); }) } 

: クリックして 'はい' ボタンは、メソッドYesHandlerを実行しますか? –

関連する問題