In ComponentA I have a variable that gets its value from a variable in a shared data class. ComponentA looks like this:
import { SharedData } from '../../shared/shared.data';
...
export class ComponentA implements OnInit {
TheSelectedClient = this.SharedData.SelectedClient;
constructor(
private SharedData: SharedData,
) { }
And the shared data class looks like this:
export class SharedData {
SelectedClient = 'Client One';
But when I update the SharedData.SelectedClient = 'Client Two'
from a different component, then TheSelectedClient
in ComponentA doesn't update by itself. How do I make TheSelectedClient
automatically update when SharedData.SelectedClient
updates?
I feel like the answer is in Observables but I don't exactly understand how to use it. I tried reading up on it but it is hard to understand :(