How to pass a GET parameter on a URL in Angular 4+? Using the route system

0

I need to insert a get parameter after entering the page with the URL.

For example:

I clicked here x went to the page and. link ? = parametroGet

In case this GET parameter will be an ID, which I will pass when the user clicks the specific button.

I tried to use the route system of the Angular, but I did not find anything like it, if anyone can give a clearing there thank you.

    
asked by anonymous 22.05.2018 / 14:57

1 answer

0

Well, I found a form that meets my need, for example:

<a class="icon-plus-details" [routerLink]="['/', linkDetail]" [queryParams]="{id: ownerId}"></a>

This

[queryParams]="{id: ownerId}"

It inserts for me in the url returned a parameter get: url_example? id = 12 for example.

After that, I use the way the router captures a get value present in a current url. Within the component that is the result of the selected route, you do the following ...

Make all necessary imports and etc. from RouterParam, in case:

import { ActivatedRoute, Router } from '@angular/router';

functionExample() {
const id = this.routerParam.snapshot.queryParams['id'];
}   

By doing this you can capture the get present in the url and work with it.

    
22.05.2018 / 17:31