Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Angular 2 - passing data between routes

Avatar of ank5
ank5Flag for India asked on
Angular
1 Comment1 Solution4676 ViewsLast Modified:
I have 2 routes in my application - /search/criteria and /search/results.

In the search criteria component, user fills the search criteria and clicks on the search button. This button calls a function (onSearch) and the form values are passed as an input. It then routes the user to search results component.

onSearch(formValues) {
     console.log(formValues);
     this.router.navigate(['/search/results']);
  }

How can I pass the formValues (Javascript object which contains search criteria entered by the user) to the search results component? In the search results component, I would be executing the search (using the service) and displaying the results to the user in a grid.

Since the search execution is done in a service, I could also call this service from the onSearch method. But then the question would be how to pass the results to the search results component (so that it can render them in a grid).

What would be a better approach?