我正在尝试使用 Angular Bootstrap Modal 指令(http://angular-ui.github.io/bootstrap/ http://angular-ui.github.io/bootstrap/)如下,在我的控制器中打开模态:
function customerSearch() {
var modalInstance = $modal.open({
templateUrl: 'app/customer/customers.modal.html',
controller: 'customers.modal'
});
modalInstance.result.then(function(selectedCustomer) {
console.log(selectedCustomer);
});
}
在模态控制器中:
var controllerId = 'customers.modal';
angular.module('app').controller(controllerId,
['$modalInstance', customersModal]);
function customersModal($modalInstance) {
// Modal controller stuff
}
但是当我这样做时,我收到以下错误:
Unknown provider: $modalInstanceProvider <- $modalInstance
如果我拿出来$modalInstance
,它有效,但我显然没有引用调用控制器中的模式。
Edit
我不知道是否值得注意,但我使用的是 Controller As 语法:
<div class="container-fluid" data-ng-controller="customers.modal as vm">
应用程序依赖项:
var app = angular.module('app', [
// Angular modules
'ngAnimate', // animations
'ngRoute', // routing
'ngSanitize', // sanitizes html bindings (ex: sidebar.js)
// Custom modules
'common', // common functions, logger, spinner
'common.bootstrap', // bootstrap dialog wrapper functions
// 3rd Party Modules
'ui.bootstrap', // ui-bootstrap (ex: carousel, pagination, dialog)
'breeze.directives', // breeze validation directive (zValidate)
]);
我创建了一个 plunker,它在这里显示了问题:http://plnkr.co/edit/u8MSSegOnUQgsA36SMhg?p=preview http://plnkr.co/edit/u8MSSegOnUQgsA36SMhg?p=preview