AngularJS,如何更改查询字符串
AngularJS, how to change query string
例如,我有一个url:http://local.com/
。当我在SearchController
中调用函数时,我想设置text=searchtext
并获得如下url: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
});
最终的url将类似于:
http://localhost/path/to/new/url?text={{$scope.text}}&sorted={{$scope.sorted}}
另一种方法是手动设置:
$location.url('/path/to/new/url?text' + $scope.text + '&sorted=' + $scope.sorted);
相关文章:
- 如何有效地将游戏数据存储在URL查询字符串中
- 从查询字符串参数推断出正确的数据类型
- AngularJS:获取链接中没有哈希的查询字符串值
- AngularJS,如何更改查询字符串
- 如何将activeadmin查询字符串传递给batch_action
- 如何从查询字符串中的输入字段发回文本
- Django在使用AJAX时没有接收到新的查询字符串
- 使用查询字符串方法清除浏览器缓存
- 用于刷新的Javascript更改查询字符串
- 我想将查询字符串变量添加到JSON名称/值对中
- 将查询字符串值从页面传递 asp.net 到 iframe
- jqueryajax生成查询字符串,如果未定义则不通过
- 如何将查询字符串传递到HTML框架
- AngularJs将查询字符串发布到c#控制器
- Jquery - 从查询字符串中获取“#”值之后,而不是在“?”符号值之后获取
- 在 JavaScript 中将查询字符串传递给 Web 服务 (ASP.NET)
- 在查询字符串中查找 where 子句
- POST encodeURI查询字符串内部服务器错误 500
- JavaScript:从具有使用 # 符号的路由的 URL 获取查询字符串
- 更改链接 URL 中的路径名,同时保持查询字符串不变