2014-09-25 31 views
1

我配置ng-view像如下:如何在使用module.config/ng-view時使用href ID?

angular.module("app", ["ngRoute"]) 
    .config(["$locationProvider", "$routeProvider", function($locationProvider, $routeProvider) { 
     $locationProvider.html5Mode(true); 
     $routeProvider 
     .when("/", { 
      templateUrl: "views/home.html", 
      controller: "homeCtrl" 
     }) 
     .otherwise({ 
      redirectTo: "views/error.html" 
     }); 
    }]); 

的事情是,現在,只要我點擊喜歡的東西下面,它重定向我到error.html頁面。

<a href="#mobile_app">Mobile</a> 

而且,我看到一個空白頁,而它應該顯示error.html內容。這個過程沒有錯誤。

我如何在這種情況下href ID?另外爲什麼error.html頁面沒有顯示(即使我不希望它顯示,如果用戶點擊一個ID,我想知道它爲什麼不顯示)?

回答

0

試試這個,希望能夠解決你的問題。

<a href="#/mobile_app">Mobile</a> 

並且在路由配置中,您必須捕獲/ mobile_app。

+0

你是什麼意思「路由配置你必須趕上/ mobile_app」?我並沒有改變視圖,只是使用特定的id來標記偏移量。 – Elfayer 2014-09-25 11:35:58

+0

我的意思是,.when(「/ mobile_app」,{ templateUrl:「views/home.html」, controller:「homeCtrl」 }) – katmanco 2014-09-25 11:37:45

相關問題