How do I share data between 2 different components from 2 different modules?
I have a dashboard module and a preference module, each with their respective components: dashboard.component.ts and preference.component.ts
In order to pass data between these components, I created a bar.service.ts service with the following code:
private messageSource = 'orderView';
changeMessage(message: string) {
this.messageSource = message;
}
The preference.component.ts file includes the following code:
this.bar.changeMessage('groupByView');
And the dashboard.component.ts contains:
console.log(this.bar.messageSource);
Both modules are accessed through routing, with the preference module displaying the preference page and the dashboard module displaying the dashboard page.
However, when a user is on the preference page and changes the messageSource to 'groupByView', it does not reflect on the dashboard page.
The dashboard page always shows the value 'orderView' in the messageSource.