【发布时间】:2014-01-28 00:47:34
【问题描述】:
我正在尝试使用 Angular 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,它可以工作,但我显然没有引用调用控制器中的模态..
编辑
不知道是否值得注意,但我使用的是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
【问题讨论】:
-
已创建自定义指令或使用angular-ui.github.io/bootstrap 指令
-
抱歉,我忘了说我正在使用在该网址找到的那个:angular-ui.github.io/bootstrap
-
好吧,你有一种很奇怪的方式来分三步声明控制器。如果 Angular 难以找到函数,可能会弄乱名称解析。
-
你能说明你在哪里声明你的模块的依赖吗?
-
我发现以这种方式管理和执行日志记录操作更容易
标签: angularjs twitter-bootstrap