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

查看:44
本文介绍了如何访问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中对Router的工作进行记录,但是您可以在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天全站免登陆