-3

I want to pass the data through router in Angular 4.

I am passing data from following function

onEdit(event)
{
    console.log(event.data);

            this.router.navigate(['pages/details'],event.data);


} 

And I am receiving it like follows:

export class DetailsComponent {
data : any;
 constructor(private route: ActivatedRoute) {

        this.route.params.subscribe(params => {
        this.data = params;
            console.log(params);
        });
        console.log(this.data);
    }
}

But its not giving me the data I have passed. Any help?

Faisal Amdani
  • 109
  • 14

1 Answers1

0

If you want to pass via queryParams, you can try

this.router.navigate(['pages/details'], { queryParams: event.data });

Second parameter of the navigate method accepts an object of type NavigationExtras.

Suren Srapyan
  • 66,568
  • 14
  • 114
  • 112