代码几乎直接来自ui-bootstrap教程。我的主页上有一个按钮,用于打开模态窗口,但我在开发工具中收到的错误是:
Error: [$injector:unpr] Unknown provider: $uibModalInstanceProvider <- $uibModalInstance <- modalController
并在此之后每次点击都会在错误消息中添加modalController
,例如
Error: [$injector:unpr] Unknown provider: $uibModalInstanceProvider <- $uibModalInstance <- modalController <- modalController
Error: [$injector:unpr] Unknown provider: $uibModalInstanceProvider <- $uibModalInstance <- modalController <- modalController <- modalController
home.js
'use strict';
angular.module('myApp')
.controller('homeCtrl', ['$q', '$state', '$timeout', '$scope', '$http', '$filter',
'$uibModal', function($q, $state, $timeout, $scope, $http, $filter, $uibModal){
$scope.open = function (size){
var modalInstance = $uibModal.open({
animation: $scope.animationsEnabled,
templateUrl: 'app/main/searchModal.html',
controller: 'modalController',
size: size,
resolve: {
items: function () {
return $scope.items;
}
}
});
modalInstance.result.then(function (selectedItem) {
$scope.selected = selectedItem;
}, function () {
});
};
...
modalcontroller.js
'use strict';
angular.module('myApp')
.controller('modalController', ['$scope', '$uibModalInstance', function($scope, $uibModalInstance) {
$scope.items = items;
$scope.selected = {
item: $scope.items[0]
};
$scope.ok = function () {
$uibModalInstance.close($scope.selected.item);
};
$scope.cancel = function () {
$uibModalInstance.dismiss('cancel');
};
$uibModalInstance.close();
}]);
答案 0 :(得分:1)
问题在于我们(图书馆)的结尾。当我们发布0.14.0并添加了所有uib
前缀时,我们错过了将其添加到modalInstance
。该问题已在0.14.3中修复。
要在0.14.0 - 0.14.2中修复此问题,只需使用$modalInstance
,并注意当您升级到1.0时,您需要更改为$uibModalInstance
或代码将再次barf
Here's a link关于GitHub的相关问题。