2016-06-21 8 views
1

私は、アクションを実行する前にポップアップ警告モーダルを提示したいと考えています(この場合はを削除します)。モーダルでokayをクリックすると、cancelをクリックすると処理が続行されます。角モーダルリターン約束

これを行うには、最初の呼び出しである$rootScope.openDirections('warning').then(...にチェーンに沿ってモーダルの約束を返そうとしています。そこで何をすべきかを決めることができます。

私はエラーを取得していますが:。

$ rootScope.openDirections(...)、関数ではありませんat Scope.$scope.deleteObj

約束が返されていないことを私に告げる:

$scope.deleteObj = function (id, type) { 
     $rootScope.openDirections('warning').then(function (res) { 
      // Do Stuff 
     }, function (err) { 
      console.log('ERROR', err); 
     }); 

これは$ rootScope関数を呼び出します。(私はここでは、オブジェクトタイプが約束です...ので、元の発信者に今戻ることができないことを参照してください?)

方向性を開くために Modal工場を呼び出し
$rootScope.openDirections = function (type) { 
     // A Promise: Object {result: Promise, opened: Promise, rendered: Promise} 
     return Modal.showDirections(type); 
    }; 

は、モーダル:

message.htmlモーダルテンプレートレンダリング
 return { 
      ... 
      showDirections: function(type) { 
       return $modal.open({ 
        backdrop: 'static', 
        templateUrl: 'modal.html', 
        controller: 'directionsCtrl', 
        resolve: { 
         // Display custom modal template 
         obj: function() { 
          if (type === 'markdown') { 
           return { 
            template: '/modals/directions.html' 
           }; 
          } else { 
           return { 
            template: '/modals/message.html' 
           }; 
          } 
         }, 
         testID : function() { 
          return 'WHAT DO I RETURN HERE?'; 
         } 
        } 
       }); 
      } 

:モーダルためdirectionsCtrlを使用しています

<div class="admin-directions"> 
    <div class="directions"> 
     ARE YOU SURE YOU WANT TO DELETE THIS? 
    </div> 
    <p class="dismiss-admin-help" ng-click="okay()">Okay</p> 
    <p class="dismiss-admin-help" ng-click="cancel()">Cancel</p> 
</div> 

angular 
    .module('DDE') 
    .controller('directionsCtrl', ['$rootScope', '$scope', '$modalInstance', 'Modal', 'obj', 'Auth', 'VARS', '$route', '$location', 'testID', 
     function ($rootScope, $scope, $modalInstance, Modal, obj, Auth, VARS, $route, $location, testID) { 

      $scope.template = obj.template; 

      $scope.testID = ''; 

      /** 
      * Dismiss modal 
      */ 
      $scope.ok = function() { 
       $scope.testID = 'okay'; 
       return $modalInstance.result($scope.testID); 
      }; 

      $scope.cancel = function() { 
       $scope.testID = 'cancel'; 
       return $modalInstance.result($scope.testID); 
      }; 

    }]); 

答えて

1

$をmodal.openは$ modalInstancを返しますそれは約束である結果と呼ばれる性質を持っています。 .then()を呼び出す必要があります。だからあなたの場合には、あなたがこの希望:

$rootScope.openDirections('warning').result.then(function (res) { 
     // Do Stuff 
    }, function (err) { 
     console.log('ERROR', err); 
    }); 

またはその代わりに、あなたのopenDirections方法では、あなただけの約束返すことができます:

 showDirections: function(type) { 
      return $modal.open({ 
       //all your current stuff stays the same here 
      }).result; //<-- notice that you are now returning the promise 
     } 
+0

大丈夫、私の '$ modal'インスタンスは、同じ範囲内ではありませんコントローラではなく、それ自身の工場内にある。したがって、元の呼び出し元に戻すために、工場内で正確に何を解決するのですか? – Growler

+0

それはどういう意味ですか?あなたが私の提案したことをしたときにあなたのエラーは消えましたか? – mcgraphix

+0

'$ scope.ok'と' $ scope.cancel'ボタンはモーダルでは機能しません – Growler