角度注入错误:无法实例化模块

时间:2016-03-08 00:49:22

标签: angularjs dependency-injection

我正在尝试将我的角度应用程序分离到自己的文件中,但现在得到依赖注入错误并且不确定原因。简化angular-app.js,错误如下:

var app = angular.module('angularApp', ['ui.router']);

app.config(['$urlRouterProvider', '$stateProvider'], function($urlRouterProvider, $stateProvider){
    $urlRouterProvider.otherwise('/browse/overview.html');
})

和错误:

Failed to instantiate module angularApp due to:
Error: [$injector:modulerr] http://errors.angularjs.org/1.3.4/$injector/modulerr?p0=u...)
    at Error (native)
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.3.4/angular.min.js:6:416
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.3.4/angular.min.js:35:350
    at r (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.4/angular.min.js:7:302)
    at g (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.4/angular.min.js:34:428)
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.3.4/angular.min.js:35:93
    at r (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.4/angular.min.js:7:302)
    at g (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.4/angular.min.js:34:428)
    at Lb (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.4/angular.min.js:38:146)
    at d (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.4/angular.min.js:17:339

1 个答案:

答案 0 :(得分:1)

您的错误就在这一行:

app.config(['$urlRouterProvider', '$stateProvider'], function($urlRouterProvider, $stateProvider){

您需要在函数声明后关闭括号,如下所示:

app.config(['$urlRouterProvider', '$stateProvider', function($urlRouterProvider, $stateProvider){
    $urlRouterProvider.otherwise('/browse/overview.html');
}])