简体   繁体   English

使用Module.Controller()语法的AngularJS UI Bootstrap 0.6.0模态

[英]AngularJS UI Bootstrap 0.6.0 Modal with Module.Controller() syntax

Instead of defining the controller for my modal instance like this: 而不是像这样为我的模态实例定义控制器:

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

I want to define it using Module.Controller() syntax: 我想使用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());
            });
        };
    }]);

In $modal.open, how do I reference ModalInstanceCtrl correctly? 在$ modal.open中,如何正确引用ModalInstanceCtrl?

You put it in quotes, like this controller: 'ModalInstanceCtrl', 您将其用引号引起来,例如此controller: 'ModalInstanceCtrl',

Here is an example based on the demo in angular-ui bootstrap 这是一个基于angular-ui引导程序中的演示的示例

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM