2014-11-05 166 views
0

我想我的手在角度路由,但它不工作,我也沒有得到任何錯誤在console.Can有人請指導我我做錯了什麼?路由不能在角度spa工作

**** **** app.js

var routingApp = angular.module('routingApp', ['ngRoute']); 
routingApp.config(function ($routeProvider) 
{ 
    $routeProvider.when('/', { 
     templateUrl: '/views/home.html', 
     controller: 'mainController' 
    }) 
    .when('/about', { 
     templateUrl: '/views/about.html', 
     controller: 'aboutController' 
    }) 
    .when('/contact', { 
     templateUrl: '/views/contact.html', 
     controller: 'contactController' 
    }); 
}); 

mainController

routingApp.controller('mainController', function ($scope) 
{ 
    $scope.message = 'Hey its home page'; 
} 
) 

;

aboutController

routingApp.controller('aboutController', function ($scope) 
{ 
    $scope.message = 'this app is about routing'; 
}); 

的index.html

**

<body ng-controller="mainController"> 
     <nav class="nav navbar-default"> 
      <div class="container"> 
       <div class="navbar-header"> 
        Angular JS Routing 
       </div> 
       <ul class="nav navbar-nav navbar-right"> 
       <li><a href="/">Home</a></li> 
       <li><a href="#/about">About</a></li> 
       <li><a href="#/Contact">Contact</a></li> 
       </ul> 
      </div> 
     </nav> 
     <div id="main"> 
      <div ng-view></div> 
     </div> 
     <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular.min.js"></script> 
     <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular-route.js"></script> 
     <script src="app.js"></script> 
     <script src="controller/mainController.js"></script> 
     <script src="controller/contactController.js"></script> 
     <script src="controller/aboutController.js"></script> 

** 

回答

0

存在缺失的指令ng-app,而不是相加NG-控制器body,請加ng-app="routingApp"

請ALSE提高鏈路共同聯繫頁面,而不是#/Contact,請使用#/contact

0

請檢查您的href

<li><a href="/">Home</a></li> 
<li><a href="#/about">About</a></li> 
<li><a href="#/Contact">Contact</a></li> 
+0

我的部分觀點在裏面查看folder.how重定向這些。我試過這些,但它不工作。index.html是外部查看文件夾 – F11 2014-11-05 04:18:18