javascriptangularjstwitter-bootstrapangular-ui-bootstrapui.bootstrap

Cannot inject ui.bootstrap into my module


I'm trying to inject ui.bootstrap into my module, called 'app'. I already included the ui-bootstrap javascript file into my html, but I get below error no matter what I do:

Uncaught Error: [$injector:modulerr] 

If I remove any dependencies to ui.bootstrap, the error goes away.

Order of js imports in head tag, all of which load up fine. (checked in Chrome dev tools)

<script src="/Scripts/angular.min.js"></script>
<script src="/Scripts/angular-route.js"></script>
<script src="/Scripts/angular-ui-router.min.js"></script>
<script src="/Scripts/angular-animate.js"></script>
<script src="/Scripts/ui-bootstrap-tpls-1.2.5.min.js"></script>

Current AngularJS version is 1.5.2

app.js

(function () {
    'use strict';

    var app = angular.module('app', [
        // Angular modules
        'ngRoute',
        'ngAnimate',
        'ui.bootstrap',
        // Custom modules
        // 3rd Party Modules
        'ui.router'
    ]);

    app.config(['$locationProvider', '$stateProvider', '$urlRouterProvider', '$modal', function ($locationProvider, $stateProvider, $urlRouterProvider, $modal) {
        $locationProvider.html5Mode(true);

        $urlRouterProvider.otherwise('/');
        $stateProvider
            .state('home', {
                url: '/',
                controller: 'frontpageController',
                templateUrl: 'app/views/frontpage.html',
                data: {
                    authorize: false 
                }
            })
            .state('login', {
                url: '/login',
                controller: 'loginController',
                templateUrl: 'app/views/login.html',
                data: {
                    authorize: false
                }
            })
            .state('profile', {
                url: '/profile/:userId',
                controller: 'profileController',
                templateUrl: 'app/views/profile.html',
                data: {
                    authorize: true
                }
            })
            .state('error', {
                url: '/error',
                controller: 'errorController',
                templateUrl: 'app/views/404.html',
                data: {
                    authorize: false
                }
            })
    }]);

    app.run(function ($rootScope, loginService) {
        $rootScope.$on('$stateChangeStart', function (event, toState, toParams) {
            var authorize = toState.data.authorize;

            if (authorize && typeof $rootScope.currentUser === 'undefined') {
                event.preventDefault();
                // get me a login modal!
                loginService()
            }
        });

    });

})();

Solution

  • You cannot inject services in module config, it only allow providers. $modal is renamed as $uibModal in last ui-bootstrap too (to rename in your controllers).

    So remove '$modal' from your .config inject it only when you use it.