0

I want to show a message on the login component if the user came from a successful registration process. I know that the question "how to pass data from one component to another" is very common But a few times someone know a technique that is very easy and good to apply. The components are not in a parent/child structure, I don't want to use query strings (worst solution in my opinion), preferably I don't want to go throught all the trouble to create a shared service.

Is there some way to do something like:

   this.router.navigateByUrl('login', {data_available_only_in_this_request: true})

I am redirecting the user if the registration was successful to the login component and passing some data. Here I am only showing how easy I want things to be.

I am searching an easy way to do this, I think creating a facility only to show a message too much.

2 Answers2

0

there is actually a way to achieve this, by storing data in the object and then set to local storage. example:

 let obj={
name:'',
item:''}


localStorage.setItem('object',JSON.stringify(obj));

then where ever you want to get use this,

let x =  localStorage.getItem('object')
var y= JSON.parse(x); 

IF you are really not interested to use HelperComponent this would help you better.

-1

You can create a data service for pass data from one component to another component.

Please check this link's data.service.ts section for more detail.

if this method is not working for you then store data in localstorage with custom controller id and fetch from localstorage where you need it.

Dhaval
  • 868
  • 12
  • 22
  • I know ,that's the only "good" solution I can think of. But I only wish it could be an easier way. –  Feb 07 '19 at 14:09
  • Then store your data in localstorage with component id and fetch in other component – Dhaval Feb 07 '19 at 14:29