Home >Web Front-end >JS Tutorial >How to operate Angular5 routing parameters

How to operate Angular5 routing parameters

php中世界最好的语言
php中世界最好的语言Original
2018-06-01 14:46:321400browse

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>

Get parameters js

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

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
 }

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!

Statement:
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