2014-01-07 105 views
1

嘿,我已經開始學習angularJS,我很新,所以我覺得我最好的選擇就是問問別人。

所以我的$ routeProvider並沒有將我路由到任何真正的當我運行它不會加載任何partials。

我正在使用的當前代碼。

angular.module("list" , ['ngRoute' ]) 
config(function ($routeProvider) { 

    $routeprovide. 
     when("/", {templateUrl:"/partials/list.html"}) 
    }) 

我的index.html

<!doctype html> 
<html ng-app="list"> 
<head> 
<meta charset="UTF-8"> 

    <link rel="stylesheet" href="css/Style.css"> 
    <link rel="stylesheet" href="css/bootstrap.css"> 
    <title>Angular Routing!</title> 
    </head> 
    <body> 
    <div ng-controller="AppCtrl" class="container"> 
    <a href="#lijst"> 
     <h2>The List!</h2> 
    </a> 

     <div ng-view> </div> 

    </div> 



<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/angularjs/X.Y.Z/angular-route.js"></script> 
<script type="text/javascript" src="js/angular.min.js"></script> 
<script type="text/javascript" src="js/main.js"></script> 
<script type="text/javascript" src="js/bootstrap.js"></script> 
</body> 
</html> 

編輯:我使用USBWebserver應用

控制檯錯誤運行:

> Failed to load resource: the server responded with a status of 404 (Not Found) 
http://ajax.googleapis.com/ajax/libs/angularjs/X.Y.Z/angular-route.js 

Uncaught ReferenceError: config is not defined main.js:2 

Uncaught Error: Bootstrap requires jQuery bootstrap.js:7 

Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.2.7/$injector/modulerr?p0=list&p1=Error%3A%20…20at%20e%20(http%3A%2F%2Flocalhost%3A8080%2Fjs%2Fangular.min.js%3A29%3A115) angular.min.js:30 
+0

你如何運行它以及控制檯消息是什麼?另外,顯示你的index.html文件。 –

+0

我已經添加了我的index.html並回答了你的問題,我使用USBWebserver運行它,我知道它對於其他任何事情都是無用的,但是我太習慣它了:p。 – BWl

+0

@BWI更新了答案。 –

回答

3

首先,你的角路線.js必須包含在角度本身之後

其次,你使用的是一些routeprovide,和$routeProvider注入

你應該這樣做:

angular.module("list" , ['ngRoute' ]). 
config(function ($routeProvider) { 

$routeProvider. 
    when("/", {templateUrl:"/partials/list.html"}) 
}); 

你也忘了配置方法前點。

這:

<script type="text/javascript" src="js/angular.min.js"></script> 
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/angularjs/X.Y.Z/angular-route.js"></script> 

而且,現在看來,你的Bootstrap.js需要的jQuery被列入前。

+0

奧克我已經想出了什麼問題是公平的說你做了所有繁重的工作:p CDN是不正確的,它應該是 https://ajax.googleapis.com/ajax/libs/angularjs/1.2。 0rc1/angular-route.min.js – BWl

+0

@BWI Twitter Bootstrap依賴於jQuery,因爲它是一個jQuery插件。 – KrishnaDhungana