I need to access a Params variable sent to a child component in the parent component.
I have the following structure:
Routing: (excerpt)
{
path: 'song',
component: SongExerciseComponent,
children: [
{
path: 'reading/:id',
component: SongReadingComponent,
}
]
}
The parent component is just a template holding navigation links. I can access the :id var in the child component like so:
ngOnInit(): void {
this.route.params.forEach((params: Params) => {
if (params['id'] !== undefined) {
let id = +params['id'];
Now I need the same variable in the parent component to be used in the parent template.
Which is the most effective way to do this? Sharing a service? https://angular.io/docs/ts/latest/cookbook/component-communication.html#!#parent-and-children-communicate-via-a-service