如何删除AngularJS的GET参数? [英] How to remove GET params with AngularJS?

查看:96
本文介绍了如何删除AngularJS的GET参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 #/ order / 123?status = success 

命中路径'/ order /:id'并且使用 OrderCtrl



一旦我们访问 $ routeParams.query ,我们想要将url清除为 #/订单/ 123 。如何实现这一点?

解决方案使用 $ location 服务,您可以通过为其分配一个空值来移除搜索参数:


$ b

  $ location.search('状态',null); 

但是您应该注意,默认情况下,这将重新加载当前路线。如果您不想重新加载当前路线,您可以在路线定义中禁用该路线:

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

但是 $ routeUpdate 仍会触发,可以作出反应。


#/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?

解决方案

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.

这篇关于如何删除AngularJS的GET参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆