Angular ngRoute无法正常工作?

Angular ngRoute无法正常工作?

问题描述:

我试图配置一个基本的角度应用程序。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'? –

您写的$routProvider,它是$routeProvider

+0

对不起,这不是问题 –

+0

尝试进入本地主机:3000 /主/#/ costumers – NMO

+0

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

既然你有html5Mode设置好的为您的app.js真实的,你需要包括这在你的main.html中:

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

所以html5Mode会的工作,你可以在URL而不#访问。