0

I am in new in Angular 6. I am creating an app using Angular 6. During development I ran into a problem which is to share the data between components. Here is the code:

I have two components 1) Signup 2) Verification

Signup is opened from route /signup and verification is opened from /verification. Now what i want to pass the object from signup to verification component

Here is my sample code.

signup(){
  let someobject = {"name":"name"} // this data I want to pass in verification
  this.router.navigateByUrl('/verfication);
}

// second is the verfication component
export class verfication Component implements OnInit {

    constructor() { }

    ngOnInit() { }
}
ashish.gd
  • 1,713
  • 1
  • 14
  • 25
Karan
  • 1,048
  • 2
  • 20
  • 38
  • This post covers it https://stackoverflow.com/questions/44864303/send-data-through-routing-paths-in-angular – ashish.gd Apr 05 '19 at 14:11

2 Answers2

0

You can use a service to store the data. And both the components can get the data from the service

Say let the service contain two methods and variable Const data; SetData(newdata) // set the variable here getData() // return the variable here When u get the date a, call setData method of service. And in another component u can get the data using getData method

Shilpa J
  • 41
  • 6
0

A simple solution is to have a global service injected into main module and share data using local variable of that service

Mukesh
  • 69
  • 7