2017-10-11 12 views
1

내가 겪고있는 문제는 설명하기가 약간 어렵다.하지만 (앵귤러) 약속이 틀릴 수도 있지만 여전히 ...

다음 상황을 훌륭하게 처리하려고합니다. 일반적으로 dialogServiceconfirm 메서드를 제공하기 위해 yes 버튼을 클릭 할 때 확인 된 약속을 반환하는 방법을 사용한다고 가정 해 봅시다. 실제로 확인이 성공했을 때를 의미합니다. 그러나, yes 확인에서 실행될 내부 async 작업이 완료 될 때까지 대화 상자가 열린 상태로 유지되기를 원합니다. 그리고 그것이 성공적으로 끝나면, 대화 상자가 닫히고, 그렇지 않으면 열려 있어야합니다. 코드에서

은 (완벽하게)이처럼 보이는 것 그 :

외부 코드 :

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를 실행합니다? –