2016-08-25 64 views
0

我正在使用angularjs NG路由切換高炮的觀點,我做了它的工作,下面的示例代碼:角度,NG-HREF使頁面刷新

HTML: 映射 新產品 angularjs

.config(function ($routeProvider) { 
$routeProvider 
    .when("/", { 
     templateUrl: "/MbfProduct/Main" 
    }) 
    .when("/Mappings", { 
     templateUrl: "/Mappings" 
    }) 
.when("/Products", { 
    templateUrl: "/Products" 
})  

})

那麼一切都OK只是我不得不添加「#」在NG-href屬性所以頁面沒有得到刷新。

所以我的問題我怎麼能得到結果,我的意思是沒有頁面刷新,沒有'#'在HREF?

+1

您的要求是什麼? –

+0

我更新了問題 –

回答

0

您可以在控制器中編寫一個更改視圖的函數。您必須使用$location供應商在視圖之間切換。有一種名爲path的方法進行切換。

就是這樣。

app.controller("TestCtrl", function($scope, $location){ 

$scope.changeView = function(){ 
    $location.path("/Mappings"); 
} 
}) 

,並呼籲錨標記ng-clickchangeView功能,只是刪除ng-href標籤乾脆。如果這不起作用,您也可以使用ng-href="javascript:void(0)"來給錨標籤賦予無效鏈接。