角度使用ui.router注入问题

时间:2016-03-08 21:19:52

标签: angularjs

我已经构建了一个简单的角度,我正在尝试实现ui-router,特别是$ UrlRouteProvier.otherwise,如果输入不存在的某些内容,则会重定向到某个url。我在尝试加载我的页面时遇到以下异常,似乎无法找到错误。所有帮助表示赞赏。代码和错误如下。

Angular app:

var app = angular.module('myApp', ['ui.router','ngAnimate', 'ui.bootstrap']);

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

错误:

Failed to instantiate module myApp due to:
Error: [$injector:nomod] http://errors.angularjs.org/1.3.4/$injector/nomod?p0=gcIm...
    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:21:334
    at a (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.4/angular.min.js:20:483)
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.3.4/angular.min.js:21:218
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.3.4/angular.min.js:35:76
    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

注意:如果我从依赖项列表中删除ui.router

,一切正常

2 个答案:

答案 0 :(得分:2)

看起来你没有加载ui-router代码。尝试包括:

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.18/angular-ui-router.js"></script>

答案 1 :(得分:0)

尝试编写如下的配置行:

.config(function($stateProvider, $urlRouterProvider) {