2017-02-28 32 views
0

從我的角度應用程序中,我需要從URL中刪除#值。作爲一個示例,我需要執行此參數名爲cal name的URL,然後以html頁。AngularJs在從url中刪除哈希符號(#)後使用url參數工作

例子:

這個網址:

http://localhost/angular_ex/url.html#?name=test

中:

http://localhost/angular_ex/url.html?name=test

因爲從C#WebRequest類不允許發送網頁reques t以及散列值。

我也嘗試使用這個堆棧溢出post也。

HTML代碼:

<!DOCTYPE html> 
<html ng-app="HelloApp"> 
<head> 
    <script src="./angular/angular.js"></script> 
    <script src="https://code.jquery.com/jquery-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script> 
    <script src="index.js"></script> 
    </head> 
    <body ng-controller="myCtrl"> 
     <p>Url parameter value is :{{name}}</p> 
    </body> 

</html> 

index.js

var newApp = angular.module('HelloApp', []); 
newApp.controller('myCtrl', newAppConstructor); 
newAppConstructor.$inject = ['$scope', '$location']; 

function newAppConstructor($scope, $location) { 
    $scope.name = $location.search().name; 
} 
+0

也許這可以幫助你http://stackoverflow.com /問題/ 16677528 /位置開關之間-HTML5和 - hashban g-mode-link-rewriting – Hosar

+1

你的路線在哪裏?你有沒有添加'$ locationProvider.html5Mode(true)' – Sravan

回答

2

試試這個答案

newApp.config(function($locationProvider) { 
    $locationProvider.html5Mode({ 
    enabled: true, 
    requireBase: false 
    }); 
    })