您好,欢迎访问一九零五行业门户网

Angular5路由传参使用详解

这次给大家带来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  }
参考http://www.jb51.net/article/139125.htm
3.js里的路径跳转
例如:path:/product,component:productcomponent,data:[{madeinchina:true}]}
获取参数的方式: activatedroute.snapshot.data[0][madeinchina]
相信看了本文案例你已经掌握了方法,更多精彩请关注其它相关文章!
推荐阅读:
js实现透明度渐变功能
vscode里使用.vue步骤详解
以上就是angular5路由传参使用详解的详细内容。
其它类似信息

推荐信息