2017-03-06 108 views
0

我想運行一個angularjs路由示例,但無法運行。 以下是代碼片段。 // main.html中
angularjs路由不工作在我的示例示例

 <body ng-app="myApp"> 

     <p><a href="#/">Main</a></p> 

     <a href="#london">City 1</a> 
     <a href="#paris">City 2</a> 

     <p>Click on the links to read about London and Paris.</p> 

     <div ng-view></div> 

     <script> 
     var app = angular.module("myApp", ["ngRoute"]); 
     app.config(function($routeProvider) { 
      $routeProvider 
      .when("/", { 
       templateUrl : "main.html" 
      }) 
      .when("/london", { 
       templateUrl : "london.html" 
      }) 
      .when("/paris", { 
       templateUrl : "paris.html" 
      }); 
     }); 
     </script> 

     </body> 
     </html> 

london.html

 <h1>London</h1> 
     <h3>London is the capital city of England.</h3> 
     <p>It is the most populous city in the United Kingdom, with a metropolitan area of over 13 million inhabitants.</p> 
     <p>{{msg}}</p> 

paris.html

<h1>Paris</h1> 
    <h3>Paris is the capital city of France.</h3> 
    <p>Th`enter code here`e Paris area is one of the largest population centers in Europe, with more than 12 million inhabitants.</p> 
    <p>{{msg}}</p> 

請幫我運行這個例子。

在此先感謝。

+0

你在控制檯得到任何錯誤? – Sujithrao

+0

是sujith ji,像這樣的錯誤 XMLHttpRequest無法加載file:/// C:/nageswar_test/paris.html。協議方案僅支持交叉源請求:http,data,chrome,chrome-extension,https,chrome-extension-resource。 –

+0

你有三個'when'狀態,你還可以添加'其他'狀態,以防萬一嗎?這可能會解決您遇到的一些問題。 – rrd

回答

0

確保您獲得角路由JS和添加引用它,在你的index.html

<script src="scripts/angular-route.js"></script>