2016-03-08 34 views
0

我已經建立了一個簡單的角度,並試圖實現ui路由器,特別是,$ UrlRouteProvier.otherwise重定向到一個特定的網址,如果不存在的東西輸入。我現在嘗試加載我的頁面時看到以下異常,但似乎無法找到該錯誤。所有的幫助表示讚賞。下面的代碼和錯誤。Angular使用ui.router注入問題

角應用:

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一切正常

+0

無關注:角版1.3.4是很老。你最好使用最新的版本。 –

回答

2

它看起來像你沒有用戶界面路由代碼加載。嘗試包括:

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

請確保在您的Angular代碼中引用它之前加載ui-router庫 –

+0

@ m1gu3l我接受了您的答案,因爲它修復了錯誤,但是routeproverider.otherwise沒有重定向到我指定的頁面。當我輸入一個隨機的URL,例如http:// localhost:8081/browse/overvieasdsw.html – GregH

+0

時,我收到一個沒有找到的空白頁面。我認爲這不是完整的解決方案,而是着眼於注入問題。嘗試使用__templateUrl__指定瀏覽/ overview.html然後重定向到該狀態的url來定義狀態。希望這可以幫助。 – m1gu3l

0

試着寫你的配置線路是這樣的:

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