2017-08-09 68 views
0
$scope.currentLocationPath = $location.path(); 

$scope.configUserPath = '/configUser'; 

    http://myurl.com/#/configUser/ 

$scope.editUserPath = '/editUser'; 

    http://myurl.com/#/editUser/1 

<div ng-hide="(currentLocationPath === configUserPath || currentLocationPath === editUserPath)>do something</div> 

我正在比較使用當前位置的路徑。對於沒有查詢字符串的網址,它的效果很好,但是它並沒有比較正確的URL和查詢字符串的路徑,如編輯用戶案例所示。AngularJS - 刪除查詢字符串和比較路徑

如何在editUser後刪除查詢字符串並將其與currentlocation進行比較?

回答

0

如果你是在你有以下URL的情況:

http://myurl.com/#/editUser/1 

然後$location.path()將返回:/editUser/1這樣你就可以在角色/分割它,得到的第二個元素,並在添加/開始(因爲split刪除每個/)是這樣的:

'/' + $location.path().split('/')[1] 

它會回報你這樣的:

/editUser 

這也適用於在這裏你有以下URL的情況下(這將返回:/configUser):

http://myurl.com/#/configUser/