我试图使用从ui-bootstrap 0.6的模态指令
这里是从ui-bootstrap页面的工作默认plunker:
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','$modalInstance','items',$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没有定义
我怎么能使这种工作使用这种方式定义控制器?
将控制器名称提供为String,与您在路由定义,指令等中完全一样:
var modalInstance = $modal.open({ templateUrl: 'myModalContent.html',controller: 'ModalInstanceCtrl',resolve: { items: function () { return $scope.items; } } });