AngularJS UI Bootstrap 0.6.0 Modal with Module.Controller()



而不是为我的模式实例定义控制器,如下所示:

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?

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

以下是一个基于angular ui bootstrap 演示的示例

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

最新更新