2014-01-05 143 views
0

我不能爲我的生活弄清楚我做錯了什麼。我正在做一些John Linquist視頻,做一些基本的AngularJS路由。當我在partials文件夾和我的index.html頁面中沒有我的表格(並且沒有使用ng-view,因此我不必配置路由選擇時,它可以正常工作。但是,我嘗試將我的表格的局部視圖與<ng-view></ng-view>然後我得到錯誤:http://goo.gl/nZAgrj(從角文檔)Angular JS的路由問題

app.js

angular.module('enterprise',[]) 
    .config(function($routeProvider){ 
     $routeProvider.when("/",{templateUrl:"/partials/list.html"}) 
    }) 
//this is the that iterated over in the partial view's ng-repeat 
function AppController($scope){ 
    $scope.crew =[ 
     {name:'Picard',description:'captain'}, 
     {name: 'Riker',description:'number 1'}, 
     {name:'Word',description:'Security'} 
    ] 
} 

的index.html

<!DOCTYPE html> 
<html> 
<head> 
    <title>Angular JS Routing</title> 
    <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css"/> 
    <link href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-glyphicons.css" rel="stylesheet"> 
</head> 
<body> 
<div ng-app="enterprise" ng-controller="AppController"> 
    <a href="/"><h2>Enterprise Crew</h2></a> 
    <ng-view></ng-view> 
    //list.html should be injected here 
</div> 

<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular.min.js"></script> 
<script src="js/app.js"></script> 
</body> 
</html> 

list.html

<table class="table table-striped" style="width: 250px"> 
    <thead> 
    <tr> 
     <td>Name</td> 
     <td>Description</td> 
     <td><i class="glyphicon glyphicon-plus-sign"></i> </td> 
    </tr> 
    </thead> 
    <tbody> 
    <tr ng-repeat="person in crew"> 
     <td>{{person.name}}</td> 
     <td>{{person.description}}</td> 
     <td><i class="glyphicon glyphicon-edit"></i></td> 
    </tr> 
    </tbody> 
</table> 

回答

0

,是它的工作這樣呢?

angular.module('enterprise',[]) 
.config(function($routeProvider){ 
    $routeProvider.when("/",{templateUrl:"/partials/list.html"}) 
}) 
.controller("AppController", ['$scope', 
    function ($scope){ 
     $scope.crew =[ 
      {name:'Picard',description:'captain'}, 
      {name: 'Riker',description:'number 1'}, 
      {name:'Word',description:'Security'} 
     ]; 
    } 
]); 

好,反應是在這裏:AngularJS 1.2 $injector:modulerr

+0

只要我不嘗試使用路由,它就會工作。 – wootscootinboogie

+0

Nix是對的,這是因爲路由js文件並未作爲模塊中的依賴項包含在內。 – wootscootinboogie