【问题标题】:AngularJS UI Bootstrap 0.6.0 Modal with Module.Controller() syntaxAngularJS UI Bootstrap 0.6.0 模态与 Module.Controller() 语法
【发布时间】:2013-11-22 23:50:09
【问题描述】:

而不是像这样为我的模态实例定义控制器:

var ModalInstanceCtrl = function ($scope, $modalInstance, items) { /*ctrl-code-here*/ };

我想使用 Module.Controller() 语法来定义它:

angular.module('MyModule', ['ui.bootstrap'])
    .controller('ModalInstanceCtrl', ['$scope', '$modalInstance', 'items', function ModalInstanceCtrl($scope, $modalInstance, items) { /*ctrl-code-here*/ }])
    .controller('ModalDemoCtrl', ['$scope', '$modal', '$log', function ModalDemoCtrl($scope, $modal, $log) {
        $scope.items = ['item1', 'item2', 'item3'];

        $scope.open = function() {

            var modalInstance = $modal.open({
                templateUrl: 'myModalContent.html',
                controller: ModalInstanceCtrl,  //what do I put here to reference the other controller?
                resolve: {
                    items: function() {
                        return $scope.items;
                    }
                }
            });

            modalInstance.result.then(function(selectedItem) {
                $scope.selected = selectedItem;
            }, function() {
                $log.info('Modal dismissed at: ' + new Date());
            });
        };
    }]);

在 $modal.open 中,如何正确引用 ModalInstanceCtrl?

【问题讨论】:

  • 你把它放在引号里。
  • 我也遇到了同样的问题:啊,真的那么简单吗? @Stewie 你是根据经验知道的吗?或者我应该在哪里找到这个?

标签: angularjs twitter-bootstrap angular-ui-bootstrap


【解决方案1】:

你把它放在引号里,像这样controller: 'ModalInstanceCtrl',

这是一个基于 angular-ui bootstrap 中的演示的示例

http://plnkr.co/edit/Xa6KqUCew9OTrtEQYjku?p=preview

【讨论】:

  • Snap,有时最简单的解决方案是最困难的解决方案。感谢您也指出我的疏忽......您好单元可测试控制器!
  • 因此失去了我生命中的 3 个小时。我想捅人!
猜你喜欢
  • 1970-01-01
  • 2018-03-12
  • 2016-02-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多