仅更改位置搜索对象的一个​​属性

时间:2016-12-26 11:45:45

标签: angularjs

根据documentation,可以在该位置设置搜索参数,如下所示:

$location.search({a: 'b', c: true});

获取位置:

http://example.com/base/index.html#!/foo?a=b&c

假设我已经在当前位置有一些搜索参数。什么是最简单和最简洁的方法来改变一个参数而不是覆盖其他参数?

1 个答案:

答案 0 :(得分:1)

您必须使用新的搜索参数获取实际的$location.search()参数和extend

例如:

var
    currentSearch = $location.search(),
    myNewSearch = { a: 'd' };

angular.extend(myNewSearch , currentSearch );

$location.search(myNewSearch);