这次给大家带来怎样操作Angular5路由传参,操作Angular5路由传参的注意事项有哪些,下面就是实战案例,一起来看一下。
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() {
let obj = this.route.queryParams["_value"];
console.log(obj);
}2.冒号形式,
例如:path:/product/:id
获取参数的方式:ActivatedRoute.params[id]
上边html代码中第一个routelink就是。
另外需配置路由
{
path:'listDetail/:id',
component:ListDetailComponent
}相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!
推荐阅读:











