1

I have a form and when user submits the form. I make a service all and get the status of the form submission. It can be error/success/exact message also. As soon as i get the response from back end, i route to new component. How do i pass the json response to new component where in it can decide what message to show i.e. error or success. One method is service. Is there any other way in angular 4 for this.

1 Answer 1

1

Unfortunately, I believe that the best answer is to just use a shared service between the two components.

The reason why the service is the best is because the router needs to serialize the data to the browsers URL bar, and the URL bar only supports a string. Therefore you wouldn't be able to pass an object through the router.

One other option would be to use localStorage and save the object that way and then just get the stored object when the next component loads. But I would probably recommend the shared service over localStorage.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.