2017-08-09 69 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/