2017-01-14 11 views
2

完全に機能する 'locals'属性を使用して、md-Dialogに情報を送信します。 ユーザーがボタンを押すと、彼は$ resourceメソッドを通していくつかの情報を送り、応答を得ます。 私のMDダイアログが閉じられた後に、その応答を表示する必要があります。 最初のコントローラにどのように応答を送信しますか?ここでAngularjs mdDialog - 最初のコントローラにデータを返す方法

は高度で>

//Main controller 
app.controller('Postulation_Ctrl', function($scope, $mdDialog,Postulation, Lista_Complejos){ 

//md-dialog function 
    $scope.showPrompt = function(ev){ 
     var parentEl = angular.element(document.body); 

    var confirm = $mdDialog.show({ 
     parent: parentEl, 
     locals: { 

      values: $scope.values, 
     }, 
     targetEvent: ev, 
     t templateUrl: 'view/example.html', 
     controller: function DialogController($scope, $mdDialog, valores, postulaciones,user_id, Postulation) { 

     $scope.result = values; 

     $scope.createPostulation = function(){ 


       $scope.postulation = {}; 
     //some logic 

     auxPostulation = new Postulation($scope.postulation); 
     auxPostulation.$save(null, function(){ 
     $scope.queryPost(); 
       ); 
      } 

     $mdDialog.hide(); 
     } 

$scope.queryPost = function() { 
    Postulation.query(function(response){ 
    $scope.postulations = response; <----------I NEED TO SEND BACK THIS RESPONSE!! 
    },function(error){ 
     console.log(error); 
    }) 
      }; 
} 

おかげ例です。

答えて

2

ダイアログコントローラには2つのオプションがあります。ダイアログを閉じるには$mdDialog.cancel(cancelData)、成功するとダイアログを閉じるには$mdDialog.hide(successData)を呼び出します。
最初のコントローラーでは、次のようになります。

var confirm = $mdDialog.show({...}).then(
function(successData) { 
    // This will be call because of $mdDialog.hide 
    // $scope.firstCtrlScope = successData; 
}, function(cancelData) { 
    // This will be call because of $mdDialog.cancel 
    // $scope.firstCtrlScope = cancelData; 
}) 
関連する問題