而不是为我的模态实例定义控制器,如下所示:
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?
答案 0 :(得分:3)
你把它放在引号中,比如controller: 'ModalInstanceCtrl',
以下是基于angular-ui bootstrap
演示的示例