你好 Stackoverflowers ;)
我在这个关于 bootstrap.ui 模态的特殊问题上挣扎了一段时间:
Uncaught Error: Unknown provider: $templateRequestProvider <- $templateRequest <- $modal
我已经尝试定义提供程序,但无法使其正常工作。
这是我的 app.js:
var app = angular.module('stelping', ['ui.bootstrap']).
config(['$routeProvider', function ($routeProvider) {
$routeProvider.
when('/', {
templateUrl: 'pages/home.html',
controller: HomeCtrl,
activetab: 'home'
}).
when('/notentool', {
templateUrl: 'pages/notentool.html',
controller: NotentoolCtrl,
activetab: 'notentool'
}).
when('/lerngruppe', {
templateUrl: 'pages/lerngruppe.html',
controller: LerngruppenCtrl,
activetab: 'lerngruppe'
}).
when('/raumreservierung', {
templateUrl: 'pages/raumreservierung.html',
controller: RaumreservierungCtrl,
activetab: 'raumreservierung'
}).
when('a', function() {
return {
restrict: 'E',
link: function(scope, elem, attrs) {
if(attrs.ngClick || attrs.href === '' || attrs.href === '#'){
elem.on('click', function(e){
e.preventDefault();
});
}
}
}}).
when('/registrieren', {
templateUrl: 'pages/registrieren.html',
controller: RegistrierungsCtrl,
activetab: 'registrieren'
}).
otherwise({ redirectTo: '/' });
}]).run(['$rootScope', '$modal', '$log', '$http', '$browser', '$timeout', "$route", function ($scope, $modal, $log, $http, $browser, $timeout, $route) {
$scope.$on("$routeChangeSuccess", function (scope, next, current) {
$scope.part = $route.current.activetab;
});
}]);
app.config(['$locationProvider', function($location) {
$location.hashPrefix('!');
}]);
这是我的 controller.js(部分只有两个新的 Ctrl):
function LerngruppenCtrl($scope, $modal, $log) {
$scope.buildings = [ 1, 5, 6 ];
$scope.rooms = [ 0, 1, 2, 3, 4 ];
$scope.currentBuilding = 1;
$scope.currentRoom = 0;
$scope.setRoom = function(room) {
$scope.currentRoom = room;
}
$scope.setBuilding = function(building) {
$scope.currentBuilding = building;
}
$scope.imgChanger = function() {
return $scope.currentBuilding+"_"+$scope.currentRoom;
};
$scope.class = "hidden";
$scope.open = function (size) {
var modalInstance = $modal.open({
templateUrl: 'myModalContent.html',
controller: 'ModalInstanceCtrl',
size: size
});
modalInstance.result.then(function () {
$log.info('Modal dismissed at: ' + new Date());
});
};
}
function ModalInstanceCtrl($scope, $modalInstance) {
$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};
}
最佳答案
该错误是由于 ui.bootstrap
的版本不匹配造成的。和 angular
. ui.bootstrap
.13 取决于 1.3x,.12 取决于 1.2x。
关于angularjs - Uncaught Error : Unknown provider: $templateRequestProvider <- $templateRequest <- $modal,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30248275/