这次给大家带来怎样操作Angular5路由传参,操作Angular5路由传参的注意事项有哪些,下面就是实战案例,一起来看一下。
1.问号后面带的参数,获取参数的方式:ActivatedRoute.queryParams[id]
例如:/product?id=1&name=iphone还可以是: [ routerLink]= "['/books']" [ queryParams]= "{bookname:'《活着》'}
代码:html
<h4>Messages</h4>
<p>Total:{{msgs.total}}</p>
<p *ngFor="let item of msgs.data">
<b>{{item.name}}</b>:
<a [routerLink]="['/next',item.id]" [queryParams]="{id:item.id, msg:item.msg, name:item.name}">{{item.msg}}</a>
<a routerLink="/final">Reply</a><p></p>
</p>获取参数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中文网其它相关文章!
推荐阅读:
以上就是怎样操作Angular5路由传参的详细内容,更多请关注php中文网其它相关文章!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号