How to remove GET params with AngularJS?

懵懂的女人 提交于 2020-01-03 08:27:21

问题


#/order/123?status=success

hits the route '/order/:id' and takes to OrderCtrl.

Once we access the $routeParams.query, we want to clear the url to #/order/123. How can this be achieved?


回答1:


Using the $location service, you can remove the search param by assigning it a null value:

$location.search( 'status', null );

But you should note that, by default, this will reload the current route. If you don't want to reload the current route, you can disable that in your route definition:

$routeProvider.when( '/order/:id', {
  // yada yada...
  reloadOnSearch: false
});

But the $routeUpdate will still fire and can be reacted to.




回答2:


A more efficient way to remove all search params would probably be

$location.search({});


来源:https://stackoverflow.com/questions/14526947/how-to-remove-get-params-with-angularjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!