我如何从一个对话框$控制器的信息到任何其他控制器? [英] How do I get information from a $dialog controller to any other controller?

查看:163
本文介绍了我如何从一个对话框$控制器的信息到任何其他控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开口,可以最小化,带来的回,在任何时间编辑并最终提交对话框。我试图做的可能不仅仅是一个对话框更多,但我希望它可以工作了。

I am opening Dialogs that can be minimized, brought-back, edited at any time and finally submitted. What I'm trying to do might be more than just a dialog but I'm hoping that it can work out.

现在我有它,这样我可以召唤我的对话框,$ P $与现有的数据,编辑对填充它,然后提交。我的主要问题,现在的问题是,我不知道怎么到最后,可能是编辑的数据发送到另一个控制器我的客户。

Right now I have it so that I can summon my dialog, pre-populate it with existing data, edit and submit. My major problem right now is that I have no idea how to send the final, possibly edited data to another controller in my client.

$范围。$广播或$范围。$发射不会出现要工作。该喷射控制器驻留在其他某种方式之外?

$scope.$broadcast or $scope.$emit doesn't appear to be working.. The injected controller resides outside of the others somehow?

这是我如何创建我的对话框:

This is how I'm creating my dialog:

$scope.openDialog = function(index){
    var html = $scope.buildHTML(index);

    var opts = {
        resizeable: true,
        backdrop: false,
        handle: ".modal-header",
        template: html,
        controller: 'OpenItemCtrl',
        resolve: {
            itemModel: function() {              
                return $scope.item[index];
            }
        }
    };

    var d = $dialog.dialog(opts);
    d.open().then(function() {
        // Right here I can determine that a dialog has closed.
        alert(index);
    });
};

这是我的控制器:

And this is my controller:

function OpenItemCtrl($scope, dialog, itemModel) {
    $scope.item= {};

    for(key in itemModel) {
        $scope.item[key] = itemModel[key];
    }

    $scope.close = function(qty, src, price){
        // I need to get these edited variables back 
        // into my controller classes somehow...
        $scope.$emit("ItemFinalized", {msg:$scope.item});
        $scope.$broadcast("ItemFinalized", {msg:$scope.item});
        dialog.close();
    };
}

我怎样才能让我的最终数据回我的控制器层次,所以我可以通过他们周围,因为我需要?

How can I get my final data back into my controller hierarchy so I can pass them around as I need to?

推荐答案

长期和短期的它,你怎么称呼它返回一个承诺对话框服务对话框的方法,当这种希望解决的一个函数被调用传递的数据被传递到对话框的控制对话框千钧一发。

Long and short of it, you call the dialog services dialog method it returns a promise, when that promise is resolved a function is called that is passed the data that is passed to the dialog close call in the dialog's controller.

http://angular-ui.github.io/bootstrap/#/dialog

$scope.opts = {
    backdrop: true,
    keyboard: true,
    backdropClick: true,
    template:  t, // OR: templateUrl: 'path/to/view.html',
    controller: 'TestDialogController'
  };

$scope.openDialog = function(){
    var d = $dialog.dialog($scope.opts);
    d.open().then(function(result){
      if(result)
      {
        alert('dialog closed with result: ' + result);
      }
    });
  };


// the dialog is injected in the specified controller
function TestDialogController($scope, dialog){
  $scope.close = function(result){
    dialog.close(result);
  };
}

这篇关于我如何从一个对话框$控制器的信息到任何其他控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆