使用angularjs获取缺少的依赖性错误

时间:2014-08-20 14:28:29

标签: angularjs

我正在获得经典的"模块' ngLocale'错误不可用" angular尝试加载我的模块时出错。我不能为我的生活找出我所缺少的依赖。这是我的app.js:

(function() {
    var app, dependencies;

    dependencies = ["ngRoute"];

    app = angular.module('myapp', dependencies);

    app.run(['$location', '$rootScope'], function($location, $rootScope) {
        $rootScope.$on('$routeChangeSuccess', function(event, current, previous) {
            $rootScope.title = current.$$route.title;
        });
    });

    app.config(['$routeProvider'], function($routeProvider) {
        $routeProvider.when('/', {
            templateUrl: 'Content/views/home.html',
            controller: 'homeController',
            title: 'Home'
        }).otherwise({
            redirectTo: '/'
        });
    });
}).call(this);

我的javascript文件按顺序正确加载。我错过了什么?

1 个答案:

答案 0 :(得分:3)

你必须在数组中包含该函数:

app.run(['$location', '$rootScope', function($location, $rootScope) {
    $rootScope.$on('$routeChangeSuccess', function(event, current, previous) {
        $rootScope.title = current.$$route.title;
    });
}]);

app.config(['$routeProvider', function($routeProvider) {
    $routeProvider.when('/', {
        templateUrl: 'Content/views/home.html',
        controller: 'homeController',
        title: 'Home'
    }).otherwise({
        redirectTo: '/'
    });
}]);