2016-10-12 106 views
-2

我想添加角度路由到我的網站。我的網站由3頁:爲什麼Angular Routing不能在我的網站上工作?

  • 的index.html(主頁)
  • home.htm
  • contact.htm
  • about.htm中

我已經使用W3Schools的教程來設置一切,並將所有內容上傳到我的網絡服務器,但儘管控制檯沒有錯誤,但當我更改鏈接時,我的內容不會顯示。請看看我的HTML和腳本角如下:

INDEX.HTML

<!DOCTYPE html> 
    <html lang="en"> 
    <head> 
     <!-- ... Header data here ... --> 
     <!--Angular--> 
     <!--Base--> 
     <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> 
     <!--Roughter--> 
     <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-route.js"></script> 
    </head> 
    <body ng-app="home" ng-controller="homeCtrl" data-ng-init="init()"> 

    <!--=== Navigation Bar ===--> 
     <nav id="nav-bar" class="navbar navbar-default"> 
       <a id="navbar-brand" href="#/"> 
       Karly Solis 
       <br> 
       Multimedia Artist 
       </a> 
       <!-- ... --> 
       <li><a id="option" href="#about">About</a></li> 
       <li><a id="option" href="#contact">Contact</a></li> 
     </nav> 
    <!--=== /Navigation Bar ===--> 

    <div ng-view></div> 

    <!-- ======= Footer ======= --> 
     <footer> 
     </footer> 
    <!-- ======= /Footer ======= --> 

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

    </body> 
    </html> 

ANGULAR

var home = angular.module('home', ["ngRoute"]); 

     home.config(function($routeProvider) { 
     $routeProvider 
     .when("/", { 
      templateUrl : "home.htm" 
     }) 
     .when("/about", { 
      templateUrl : "about.htm" 
     }) 
     .when("/contact", { 
      templateUrl : "contact.htm" 
     }) 
     }); 

頁面的其餘部分是身體的HTML頁面,沒有頭信息等我將在下面列出其中一個以供參考。

about.htm中

<!--=== Form ===--> 
    <div id="about" class="container-fluid"> 
     <div class="page-width"> 


     <!-- content ... --> 


     </div> 
    </div> 
    <!--=== /Form ===--> 

我已經上傳到Web服務器上的文件:http://kiawahislandgetaways.com/codingFun/KarlyPortfolio/Website/index.html#/

至於現在什麼也不顯示上的任何鏈接的點擊。感謝您的任何幫助!

+1

爲什麼downvote?我覺得我在列出我的問題和所有重要的代碼方面做得很好。 –

+0

你似乎仍然把你的'home.config(...)'調用**內**控制器功能 – Phil

+0

對不起,我不小心克隆了腳本文件,我更新了錯誤的版本。我現在更新了它。 –

回答

1

我檢查你的源代碼,將配置控制器外,

home.config(function($routeProvider) { 
    $routeProvider 
    .when("/", { 
    templateUrl : "home.htm" 
    }) 
    .when("/about", { 
    templateUrl : "about.htm" 
    }) 
    .when("/contact", { 
    templateUrl : "contact.htm" 
    }) 
}); 
+0

謝謝!我這樣做了,但仍然沒有顯示內容。 –

+0

現在我看不到整個路線配置 – Sajeetharan

+0

你是什麼意思? –

0

我認爲你需要刪除的前綴#在href標記一些東西像下面

<li><a id="option" href="about">About</a></li> 
 
<li><a id="option" href="contact">Contact</a></li>

相關問題