AngularJS-如何使用$location更新URL查询参数?

AngularJS-如何使用$location更新URL查询参数?,angularjs,Angularjs,我需要在我的一个服务中添加、更新和删除URL中的查询字符串参数。问题是URL似乎没有更新。我正在尝试以下方法: var updateUrlParams = function (deepLinkEvent) { if (deepLinkEvent.title !== 'bookmarkTitle') { return; } var params = $location.search(); if (deepLinkEvent.name === deepLinkEvents.r

我需要在我的一个服务中添加、更新和删除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);
我使用$window而不是$location:


我自己从来没有在$location上碰过运气,但是$window非常简单。

这也不行?!我甚至记录了url,但url在浏览器中不会更改。奇怪$log.debugurl$window.location.href=url;为什么不简单地使用$location.url$location.path呢?
$window.location.href = "url"