passing id in (click) to another component or route

1.9k views Asked by At

I need to pass an id along with a click event to another component

here is the component.ts

 editData(rcid){
      this.router.navigate(['/Editdata']);
  }

rcid is the id of the clicked item. And router"/editdata" is where the id is to be passed.

I had checked with session and local storage but it need to refresh the page when coming with another id

please help me with this. I'm new to angular

1

There are 1 answers

1
buzatto On

you can pass a second argument to navigate that implements NavigationExtras interface:

this.router.navigate(['/Editdata'], { state: { id: '123' } });

at your receiving component you can extract it:

constructor(private router: Router) {
  this.id = this.router.getCurrentNavigation().extras.state.id;
}