未捕获错误:未知提供者:$ templateRequestProvider< - $ templateRequest< - $ modal

时间:2015-05-14 22:07:52

标签: angularjs twitter-bootstrap bootstrap-modal

Hello Stackoverflowers;)

我在关于bootstrap.ui模式的这个特殊问题上花了一点时间:

  

未捕获错误:未知提供商:$ 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(部分只是两个新的Ctrls):

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');
    };
}

3 个答案:

答案 0 :(得分:30)

该错误是由于ui.bootstrapangular版本不匹配造成的。 ui.bootstrap .13取决于1.3x,.12取决于1.2x。

答案 1 :(得分:1)

我也有同样的问题。 我通过使用最新版本的angularjs,ui-bootstrap来解决它 我使用过这些版本:

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.4/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.4/angular-animate.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.4/angular-route.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.13.3/ui-bootstrap-tpls.min.js"></script>

答案 2 :(得分:0)

我也有这个问题,我使用angular 1.2.28和ui.bootstrap 0.12.1,如果我使用Jetty在Chrome上运行我的App,那么控制台将显示'Unknown provider:$ templateRequestProvider&lt; - $ templateRequest&lt; - $ modal',但如果我在Safari上运行我的应用程序将不会显示错误。