【问题标题】:AngularUI: modals, resolve and controller's locals (how to pass a model to a modal controller)AngularUI:模态、解析和控制器的局部变量(如何将模型传递给模态控制器)
【发布时间】:2013-09-08 21:10:44
【问题描述】:

无论我尝试做什么,我似乎都无法将数据传递给模态控制器。

我尝试使用解析:

   var opts = {
        backdrop: true,
        keyboard: true,
        backdropClick: true,
        templateUrl:  'views/details/basic/view.html',
        controller: 'BoxDetailsCtrl'
        resolve: {
            item: function () {
                return angular.copy(item)
            },
            price: function (){ return 100; }
        }

        this.d = this.d || $dialog.dialog($scope.opts);
        this.d.open();

我尝试传递范围:

     var opts = {
        scope: $scope
        ...

在我绝望中,我尝试破解对话服务:

 if (self.options.controller) {
                    var ctrl = $controller(self.options.controller, locals);
                    ctrl.modal = self.options.modal; // nasty hack
                    self.modalEl.children().data('ngControllerController', ctrl);
           }

没有任何效果。我似乎无法将数据传递给 BoxDetailsCtrl。有什么想法吗?

干杯,

【问题讨论】:

  • 我正在努力解决类似的问题,并找到了您未回答的问题。如果您在问题中包含 BoxDetailsCtrl 的实例化可能会有所帮助。我在将本地变量传递给使用 Module.controller(...) 声明的控制器时遇到问题,我认为这与此有关。

标签: angularjs angular-ui


【解决方案1】:

这个方法对我有用......它在coffeescript中,但你可以将它转换为js。

AngularUI separate files for modal controllers

resolve:
       primer3: ->
         $scope.primer3

然后

angular.module('assaypipelineApp').controller "ConfigureModalCtrl", ($scope,  $modalInstance, primer3) ->
  $scope.primer3 = primer3['data']

我发现我得到了一个嵌入了数据数组和 http 返回码的对象。我真的不明白为什么,但这有效。

希望对你有帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-03
    • 2023-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多