2015-01-14 60 views
0

我試圖配置一個基本的角度應用程序。Angular ngRoute無法正常工作?

我的主HTML:

<html ng-app="CostumerApp"> 
<head> 
    <title> Costumers </title> 
    <link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.css"/> 
</head> 

<body> 
    <div class="container"> 
     <div class="page-header"> 
      <h1>Costumer manager</h1> 
     </div> 

     <div class="row"> 
      <div class="col-sm-12" ng-view></div> 
     </div> 
    </div> 

<script src="bower_components/jquery/dist/jquery.min.js"></script> 
<script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script> 
<script src="bower_components/angular/angular.min.js"></script> 
<script src="bower_components/angular-route/angular-route.min.js"></script> 
<script src="js/app.js"></script> 
<script src="controllers/costumerCtrl.js"></script> 


</body> 

應用JS

angular.module('CostumerApp', ['ngRoute']) 
    .config(function ($routeProvider, $locationProvider){ 
     $routeProvider 
      .when('/costumers', { 
       controller: 'costumerCtrl', 
       templateUrl: 'views/list.html' 
      }); 

     $locationProvider.html5Mode(true); 

    }); 

costumerCtrl.js:

angular.module('CostumerApp') 
    .controller('costumerCtrl', function ($scope){ 
     $scope.costumers = []; 
    }); 

列表HTML:

<table class='table table-hover table-hover table-bordered'> 

路由不工作, 現在它沒有找到「http://localhost:3000/costumers」當我剛做http://localhost:3000它帶我到項目文件夾,而不是我的主要HTML。

我使用節點http-server並開始像那個http-server -p 3000 -a localhost。 爲什麼我的localhost:3000沒有顯示主頁?

謝謝你!

+0

不應該控制器'costumerCtrl'而不是'listCtrl'? –

回答

1

您寫的$routProvider,它是$routeProvider

+0

對不起,這不是問題 –

+0

嘗試進入本地主機:3000 /主/#/ costumers – NMO

+0

對不起,我需要:localhost:3000/costumers –

0

既然你有html5Mode設置好的爲您的app.js真實的,你需要包括這在你的main.html中:

<head> 
    <base href="/"> 
... 
</head> 

所以html5Mode會的工作,你可以在URL而不#訪問。