Avatar of ank5
ank5Flag for India

asked on 

Angular 2 - passing data between routes

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']);
  }

Open in new window


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?
Angular

Avatar of undefined
Last Comment
Julian Hansen
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Angular
Angular

Angular is a JavaScript open-source web application framework used to develop single-page applications. It aims to simplify both the development and the testing of such applications by providing a framework for client-side model–view–controller (MVC) and model–view–view-model (MVVM) architectures, along with components commonly used in rich Internet applications. Angular is the front-end part of the MEAN stack, together with Node.js runtime, Express.js backend framework and MongoDB database.

1K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo