我需要在我的服务中从URL中添加、更新和删除查询字符串参数。问题是URL似乎没有更新。我正在尝试以下几点:
var updateUrlParams = function (deepLinkEvent) {
if (deepLinkEvent.title !== 'bookmarkTitle') {
return;
}
var params = $location.search();
if (deepLinkEvent.name === deepLinkEvents.removeFragment) {
if (params[deepLinkEvent.fragmentKey]) {
delete $location.$$search[deepLinkEvent.fragmentKey];
$location.$$compose();
}
}
if (deepLinkEvent.name === deepLinkEvents.setFragment) {
$location.search(deepLinkEvent.fragmentKey, deepLinkEvent.fragmentValue);
$location.$$compose();
}
};以上内容不起作用。当我尝试用以下方式删除参数键/值时,URL不会更新:
delete $location.$$search[deepLinkEvent.fragmentKey];
$location.$$compose();且参数未用以下内容更新或添加:
$location.search(deepLinkEvent.fragmentKey, deepLinkEvent.fragmentValue);
$location.$$compose();有人能告诉我在URL中添加/更新和删除查询参数的正确方法吗?
谢谢!
更新
这也不管用
//remove param
$location(deepLinkEvent.fragmentKey, null);发布于 2014-06-26 22:43:16
我使用的不是$location,而是$window:
$window.location.href = "url"我自己从来没有得到过$location的任何运气,但是$window是非常简单的。
https://stackoverflow.com/questions/24441239
复制相似问题