2014-01-07 104 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