2017-01-14 4 views
2

완벽하게 작동하는 'locals'속성을 사용하여 md-Dialog에 정보를 보냅니다. 사용자가 버튼을 누르면 $ resource method를 통해 정보를 보내고 응답을받습니다. 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

대화 상자 컨트롤러에는 두 가지 옵션이 있습니다. 대화 상자를 닫으려면 $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; 
})