我正在尝试使用ui-bootstrap 0.6中的模式指令
这是ui-bootstrap页面上的默认工作插件:
http://plnkr.co/edit/JGBiBSeRqOnwRhYA9py8?p=preview
现在,我试图使编码样式适合有角度的种子样式,以将其包含在一个应用程序中,如下所示:
http://plnkr.co/edit/Y59rwlcNpQdijKtmjOPy?p=preview
angular.module('MyModal', ['ui.bootstrap', 'MyModal.controllers']); angular.module('MyModal.controllers', []) .controller('ModalDemoCtrl', [ '$scope', '$modal', '$log', function ($scope, $modal, $log) { $scope.items = ['item1', 'item2', 'item3']; $scope.open = function () { var modalInstance = $modal.open({ templateUrl: 'myModalContent.html', controller: ModalInstanceCtrl, resolve: { items: function () { return $scope.items; } } }); modalInstance.result.then(function (selectedItem) { $scope.selected = selectedItem; }, function () { $log.info('Modal dismissed at: ' + new Date()); }); }; }]) .controller('ModalInstanceCtrl', [ '$scope', '$modalInstance', 'items', function ($scope, $modalInstance, items) { $scope.items = items; $scope.selected = { item: $scope.items[0] }; $scope.ok = function () { $modalInstance.close($scope.selected.item); }; $scope.cancel = function () { $modalInstance.dismiss('cancel'); }; }]);
但它给出了一个错误 ReferenceError: ModalInstanceCtrl is not defined
ReferenceError: ModalInstanceCtrl is not defined
如何使用这种定义控制器的方式来完成这项工作?
像在路由定义,指令等中一样,将控制器名称提供为 String :
var modalInstance = $modal.open({ templateUrl: 'myModalContent.html', controller: 'ModalInstanceCtrl', resolve: { items: function () { return $scope.items; } } });