I have a parent component and a child component. I was trying to navigate to child component using route.navigate based on button click. Is it possible to pass an object with route.navigate to the child component?
Asked
Active
Viewed 1,948 times
2
Adrita Sharma
- 21,581
- 10
- 69
- 79
Anna
- 337
- 1
- 3
- 9
-
it is not possible to pass an object through router. you need to create a service and set the value in that and get it from another component – Anto Antony Nov 15 '17 at 04:49
-
2Possible duplicate of [How do I pass data to Angular routed components?](https://stackoverflow.com/questions/36835123/how-do-i-pass-data-to-angular-routed-components) – Aamir Khan Nov 15 '17 at 04:49
1 Answers
1
In my case I navigate from a material table to a form and pass a raw id (it is possible to pass all the raw object)
Here's my code :
<mat-cell id="idVtitle" *cdkCellDef="let row">
<button id="idValidationScreenButton" mat-button [routerLink]="['/validation', row.documentid]">{{row.title}}
</button>
</mat-cell>
And in my ValidationComponent refering to the rout validation I have something like this:
constructor(private _route: ActivatedRoute,
private _router: Router,) {
}
And then calling this this._route.params.map((params: any) => params.id) to get the param (in my case I use the param to call the backend)
private fetchDocument() {
this._route.params
.map((params: any) => params.id)
.flatMap((id: string) => this._sharedService.fetchOneDocument(id))
.subscribe((doc: any) => this.docToValidate = doc);
}
I hope this could help.
H.abidi
- 579
- 1
- 7
- 16
-
-
Hi, do you know if it is possible to pass data without having it appear on the url as query parameters? – FourtyTwo Nov 26 '18 at 06:38