【发布时间】:2017-06-19 16:04:41
【问题描述】:
我正在尝试使用 ui-bootstrap 角度模块创建带有登录表单的模式窗口。
我创建了两个控制器,但之后我意识到一个模态窗口的两个控制器太多了,所以我决定将两个控制器合并为一个。然后我遇到了3个我无法解决的错误,请帮助我。
angular.js:14239 错误:[$injector:unpr] 未知提供者:$uibModalInstanceProvider
angular.js:14239 错误:[$injector:unpr] 未知提供者:$uibModalInstanceProvider
错误:[$injector:unpr] 未知提供者:$uibModalInstanceProvider
我确信我拼写正确所有依赖项。
在将它们放在一起之前对我有用的两个控制器的代码
https://gist.github.com/anonymous/f0286abe139a02749d7b4e55d57b3fdd
最后是我通过混合它们创建的科学怪人代码。
app.controller('LoginModalCtrl', ['$scope', '$location', '$uibModalInstance', '$uibModal', 'authenticationService', function($scope, $uibModal, $uibModalInstance, $location, authenticationService) {
var $ctrl = this;
$ctrl.modalInstance = null;
$ctrl.animationsEnabled = true;
$ctrl.open = function(size, parentSelector) {
var parentElem = parentSelector ?
angular.element($document[0].querySelector('.modal-login' + parentSelector)) : undefined;
$ctrl.modalInstance = $uibModal.open({
animation: $ctrl.animationsEnabled,
ariaLabelledBy: 'modal-header',
ariaDescribedBy: 'modal-body',
templateUrl: 'loginModalContent.html',
backdropClass: "modal-backdrop",
size: size,
backdrop: true,
appendTo: parentElem,
resolve: {
items: function() {
return $ctrl.items;
}
}
});
};
$ctrl.login = function() {
//
authenticationService.login($ctrl.loginData)
.then(function(data) {
$uibModalInstance.close();
$location.url("/");
}, function(error) {
});
};
$ctrl.cancel = function() {
$uibModalInstance.dismiss('cancel');
};
}]);
【问题讨论】:
-
使依赖项的顺序相同。这意味着数组:
['$scope', ... , 'authenticationService']和function($scope, ... , authenticationService)应该具有相同的顺序。 -
我改变了,但仍然得到 [$injector:unpr] Unknown provider :(
-
我另外删除了'$uibModalInstance',现在它正在打开并且似乎工作但右上角的关闭按钮和登录按钮不起作用。
标签: angularjs modal-dialog angular-ui-bootstrap bootstrap-modal