Home > Web Front-end > JS Tutorial > body text

How to operate Angular5 routing parameters

php中世界最好的语言
Release: 2018-06-01 14:46:32
Original
1336 people have browsed it

This time I will show you how to operate Angular5routingpass parameters, and what are the notes when operating Angular5 routing parameters. The following is a practical case, let's take a look.

1. The parameters after the question mark, the way to obtain the parameters: ActivatedRoute.queryParams[id]

For example: /product?id=1&name=iphone can also be :[ routerLink]= "['/books']" [ queryParams]= "{bookname:'《《生》'}

Code: html

<h4>Messages</h4>
<p>Total:{{msgs.total}}</p>
<p *ngFor="let item of msgs.data">
 <b>{{item.name}}</b>:
 <a [routerLink]="[&#39;/next&#39;,item.id]" [queryParams]="{id:item.id, msg:item.msg, name:item.name}">{{item.msg}}</a>
 <a routerLink="/final">Reply</a><p></p>
</p>
Copy after login

Get parameters js

ngOnInit() {
 let obj = this.route.queryParams["_value"];
 console.log(obj);
}
Copy after login

2. Colon form,

For example: path:/product/:id

How to obtain parameters: ActivatedRoute.params[id]

The first routelink in the above html code is.

In addition, routing needs to be configured

{
 path:'listDetail/:id',
 component:ListDetailComponent
 }
Copy after login

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related matters on the php Chinese website Article!

Recommended reading:

How to operate JS to implement transparency gradient animation

How to use jQuery to traverse XML nodes and attributes

The above is the detailed content of How to operate Angular5 routing parameters. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!