In Angular 2, I have my routes defined in app.module.ts:
const appRoutes: Routes = [
{
path: '',
component: HomeComponent,
},
{
path: 'admin',
component: AdminComponent,
}
];
I also have an app.component which displays the menu and a search form. This app.component is connected to a service (events.service.ts) which returns an array of events. When the search form is submitted, app.component calls the service to filter the events and then grabs them:
getEvents(): void {
this.eventsService.getEvents().then(events => {this.events = events});
}
onSubmit() {
this.searchTerm = this.model.searchTerm;
this.eventsService.search(this.searchTerm).then(res => this.getEvents());
}
I would like to be able to pass this.events from the app.component down to the two routes specified in app.module (home and admin).
My home.component.ts requires the same events.service.ts, and grabs events from it in an onNgInit function, but when the events in the service have been updated via the search in app.component.ts, the events grabbed in the initialisation of home.component.ts are out of date. I would like them to be synchronised.