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

标签 angularjs controller angular-material mddialog

我使用完美运行的“locals”属性向我的 md-Dialog 发送了一些信息。
用户按下按钮后,他将通过 $resource 方法发送一些信息并获得响应。我需要在 md 对话框关闭后显示该响应。
如何将该响应发送给我的第一个 Controller ?
这是示例:

 //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);
     })
            };
} 

最佳答案

您在对话 Controller 中有 2 个选项,请调用 $mdDialog.cancel(cancelData)关闭对话框和 $mdDialog.hide(successData)成功关闭对话框。
在你的第一个 Controller 中,你有这个:

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;
})

关于Angularjs mdDialog - 如何将数据发送回我的第一个 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41650984/

相关文章:

css - 在 Angular-material 中将 more_vert 按钮对齐右侧

javascript - Angular Material主题不改变颜色

javascript - Web Workers 会对 ionic 应用程序有益吗?

javascript - 在 Controller 中使用 Angular 数据表 DTOptions

asp.net - 值不能为空。参数名称 : items (DrodownList)

javascript - 在 AngularJS 中保持不同 Controller 中的变量同步

Angular Material - 如何捕获复选框列所属的表格行

css - AngularUI Bootstrap Popover 闪烁

javascript - ui路由器嵌套 View 不显示

Angularjs:服务多个 $resource url/数据源的服务?