2014-02-25 118 views
1

我知道有很多關於路由在AngularJS中不起作用的問題。我有同樣的問題,經過數百個答案後,我決定再次發佈這個問題。我有三個文件位於c:\ intepub \ wwwroot \ angular \中的根文件夾中,這意味着我正在IIS下測試它。現在我的問題是,當我把這個URL放在瀏覽器中時:瀏覽器將其重定向到:http://localhost/angular/index.html#/,並且頁面上的文本是:測試路由角度路由不起作用

但是,根據代碼,它應該去login.html 。當我把http://localhost/angular/index.html#/test它仍然顯示相同的文本:測試路線。

任何想法?

由於

的代碼如下所示:

的index.html

<!DOCTYPE html> 
<html ng-app="app"> 
<head></head> 
<body> 
    <div> 
     Testing routes 
     <div ng-view=""></div> 
    </div> 

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

    <script> 
     var app = angular.module('app', ['ngRoute']); 

     app.config(appRouter); 

     function appRouter($routeProvider, $locationProvider) 
     { 
      $routeProvider 
       .when('/', 
        { 
         templateURL: 'login.html' 
        }) 
       .when('/test', 
        { 
         templateURL: 'test.html' 
        }) 
       .otherwise({tempate: "otherwise"}); 
     } 
    </script> 
</body> 
</html> 

的login.html

<div> 
    Login Page 
</div> 

的test.html

<div> 
    Test page 
</div> 

回答

0

試試這個,你已經錯過了控制

function appRouter($routeProvider, $locationProvider) 
     { 
      $routeProvider 
       .when('/', 
        { 
         templateURL: 'login.html',controller: 'loginCtrl' 
        }) 
       .when('/test', 
        { 
         templateURL: 'test.html',controller: 'testCtrl' 
        }) 
       .otherwise({tempate: "otherwise"}); 
     } 

的login.html

<div ng-controller="loginCtrl"> 
    Login Page 
</div> 

的test.html

<div ng-controller="testCtrl"> 
    Test Page 
</div> 

必須設置設爲起始頁TI索引頁

enter image description here

右鍵點擊Solution Explorer中的index.html頁面>點擊設置在彈出所示的啓動頁面選項。

+0

想你的建議,同樣的問題。 –

+0

請在索引頁面設置一個起始頁面,然後嘗試 –

+0

請您詳細說明一下。我沒有明白。 –

0

在已經定義了你的標記方式:

<div> 
     Testing routes 
     <div ng-view=""></div> 
    </div> 

它總是會顯示「檢測線路」爲NG提出<div ng-view="">元素內查看內容。你應該改變它適合的東西。

+0

即使刪除文本也不起作用。新的標記看起來像這樣: