gpt4 book ai didi

javascript - AngularJS,如何更改查询字符串

转载 作者:行者123 更新时间:2023-11-28 07:27:11 25 4
gpt4 key购买 nike

例如,我有这个网址:http://local.com/。当我在 SearchController 中调用函数时,我想设置 text=searchtext 并获取如下网址:http://local.com/?text=searchtext

我该怎么做?我尝试了 $location.search('text', 'value'); 但得到了这个网址:

http://local.com/#?text=searchtext

$scope.searchTracks = function() {

Search.search.get($scope.params, function(data) {
/** Set params in query string */
$location.search('text', $scope.text);
$location.search('sorted', $scope.sorted);

});

}

最佳答案

您还需要指定路径:

$location
.path('/path/to/new/url')
.search({
'text': $scope.text,
'sorted': $scope.sorted
});

最终的网址将类似于:

http://localhost/path/to/new/url?text={{$scope.text}}&sorted={{$scope.sorted}}

另一种方法是手动设置它们:

$location.url('/path/to/new/url?text' + $scope.text + '&sorted=' + $scope.sorted);

关于javascript - AngularJS,如何更改查询字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29512109/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com