详解Angular5 路由传参的3种方法
本文介绍了Angular5路由传参,一共3种方法。分享给大家,具体如下:
1.问号后面带的参数,获取参数的方式:ActivatedRoute.queryParams[id]
例如:/product?id=1&name=iphone还可以是:[routerLink]="['/books']"[queryParams]="{bookname:'《活着》'}
代码:html
Messages
Total:{{msgs.total}}
{{item.name}}: {{item.msg}}Reply
获取参数js
ngOnInit(){
letobj=this.route.queryParams["_value"];
console.log(obj);
}
2.冒号形式,
例如:path:/product/:id
获取参数的方式:ActivatedRoute.params[id]
上边html代码中第一个routelink就是。
另外需配置路由
{
path:'listDetail/:id',
component:ListDetailComponent
}
参考https://www.nhooo.com/article/139125.htm
3.js里的路径跳转
例如:path:/product,component:ProductComponent,data:[{madeInChina:true}]}
获取参数的方式:ActivatedRoute.snapshot.data[0][madeInChina]
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。
热门推荐
1 狗狗下楼训练
3 狗狗训练头盔
6 狗狗训练机构
7 训练狗狗步骤
9 狗狗能训练
10 狗狗基本动作训练方法
11 怎么训练狗狗叼饭盆
12 狗狗一岁了还能训练吗
13 训练狗狗的
14 宁波狗狗训练
15 训练狗狗拉屎
16 教狗狗训练
17 狗狗要怎么训练上厕所
18 狗狗靠的训练