2016-11-28 56 views
1

是新的角js和學習。我嘗試了一個非常簡單的例子,但它似乎一切正常,但沒有工作......我試着用兩個簡單的html文件進行路由。 HTML的內容應放在一個NG-視圖格,點擊一個用戶列表時。請幫助,在此...在此先感謝..下面是AngularJS路由不能用一個簡單的例子

<!DOCTYPE html> 
<html> 
<head> 
    <title>Main Page </title> 
    <script src="js/angular.min.js"> </script> 
    <script src="js/angular-route.min.js"></script> 
    <script> 
     var myApp = angular.module('myApp',['ngRoute']); 

     myApp.config (function ($routeProvider) { 

      $routeProvider 

      .when('/', { 
       templateUrl: 'pages/first.html', 
       controller: 'FirstController' 
      }) 

      .when('/Second', { 
       templateUrl: 'pages/second.html', 
       controller: 'SecondController' 
      }); 

     }); 

     myApp.controller('FirstController',function($scope){ 



     }); 

     myApp.controller('SecondController',function($scope){ 


     });  


    </script> 
</head> 

<body ng-app="myApp"> 
    <ul> 
     <li> Home Page</li> 
     <li> <a href="#"> Go to First Page </a> </li> 
     <li> <a href="#/Second"> Go to Second Page </li>  
     <h1> Main Page is here</h1>  
    </ul> 

    <div ng-view></div> 
</body> 
</html> 

回答

0

您還沒有關閉,第二個代碼</a>

<ul> 
     <li> Home Page</li> 
     <li> <a href="#"> Go to First Page </a> </li> 
     <li> <a href="#/Second"> Go to Second Page </a> </li>  
     <h1> Main Page is here</h1>  
    </ul> 

DEMO

+0

我試圖與plnkr。它的工作..但沒有在我的本地系統工作。我只是複製你的代碼並粘貼它..在鉻控制檯中獲取以下錯誤angular.js:10765XMLHttpRequest無法加載文件:/// C//Users/Srini/Desktop/angtest/first.html。交叉原點請求僅支持協議方案:http,data,chrome,chrome-extension,https,chrome-extension-resource。(匿名函數)@ angular.js:10765 angular.js:12520錯誤:[$ compile:tpload ] http://errors.angularjs.org/1.4.8/$compile/tpload?p0=first.html&p1=-1&p2= – srinivasan

+0

錯誤是什麼? – Sajeetharan

+0

問題是你的html文件沒有被加載 – Sajeetharan