Angularjs mdDialog - 如何将数据发送回我的第一个控制器

时间:2017-01-14 14:19:42

标签: angularjs controller angular-material mddialog

我使用' locals'向我的md-Dialog发送一些信息。完美的属性。 在用户按下按钮后,他将通过$ resource方法发送一些信息并获得响应。 我需要在我的md-dialog关闭后显示响应。 如何将该响应发送给我的第一个控制器。

以下是>

的示例
 //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 个答案:

答案 0 :(得分:4)

对话框控制器中有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;
})

答案 1 :(得分:0)

import Controller from "./controller"; //import here your controller

let {$mdDialog,$log  } = this;
    let template = require("./dialog"); // get template 
    let locals ={err ,title} //if you want to send data as parms 
    $mdDialog.show({
        controller:Controller,
        controllerAs: "vm",
        bindToController: true,
        clickOutsideToClose: true,
        template,
        locals
      }).then((data)=>{$scope.firstCtrlScope = data;}) 


 //get data using after hide a data $mdDialog.hide