如何访问 Angular2 新路由器查询字符串 [英] How to access Angular2 new router querystring

查看:41
本文介绍了如何访问 Angular2 新路由器查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从我的组件访问 querystring 参数?我有这样的网址:

How can I access the querystring parameters from my component? I have URLs like this:

http://myurl.com/myroute?myparam=1

谢谢

推荐答案

提示 RC.1 @angular/router 也已弃用.最好坚持使用 @angular/router-deprecated(因为它具有更多功能并且非常稳定)直到新的路由器发布.

Hint The RC.1 @angular/router is also deprecated. It's better to stick with @angular/router-deprecated (because it has more features and is quite stable) until a new new router is shipped.

如果您使用路由器已弃用,则 constructor(private params: RouteParams) 将使您可以访问所有参数,然后您可以通过 params.get('myparam')

If you are using router-deprecated then constructor(private params: RouteParams) will give you access to all parameters, then you can get specific parameter by params.get('myparam')

尚未记录路由器在 RC 中的工作情况,但您可以在 routerOnActivate 中获取参数

working of Router in RC is not yet documented, but you can get hold of params in routerOnActivate

routerOnActivate(curr: RouteSegment, prev?: RouteSegment, 
             currTree?: RouteTree, prevTree?: RouteTree): void {
  let myparam = curr.getParam("myparam");
}

这篇关于如何访问 Angular2 新路由器查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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