Observable are just objects where you can subscribe to new data and transfer new data to subscribers.
Observable do not participate in what can tell what. This requires Angular DI and services. You can use services to exchange observables with a specific set of components.
Angular creates a hierarchy of injectors that resembles your tree of components and directives. Each injector has a set of providers (services that are registered with the component using providers: [...] in the component or directive pointer (or bootstrap (AppComponent, [...] which is the parent of the root component injector).
DI supports one instance of the service (or another injection) for each provider. If the component is service dependent, DI starts looking for a provider in the component where it is needed. If he cannot find it, he continues searching on the original injector until he finds it or reaches the root injector.
This allows you to specify the service area. If you provide it in bootstrap() or the root component, the scope of this service is the entire application. If you provide it to another component, the scope is that component and its children.
If you want to establish a relationship between specific components, then provide a common service to the common parent and add it (add to the list of designer parameters) to the components that should interact with each other. You can see a common service such as a service bus.
Event users subscribe to observables available in this common service, senders use observables to transmit data to subscribers.
@Injectable() class VehicleService { verhicles = new Subject(); createVehicle(newVehicle) { return http.post(...)...
@Component({ selector: 'my-app', providers: [VehicleService], // provide globally ...}) export class AppComponent {}
@Component({ selector: 'b-cmp', ...}) export class ComponentB { constructor(private vehicleService:VehicleService) { vehicleService.vehicles.subscribe(data => {
@Component({ selector: 'd-cmp', ...}) export class ComponentD { constructor(private vehicleService:VehicleService) {} persisteNew(vehicle) { this.vehicleService.createVehicle(vehicle); } }
@Component({ selector: 'c-cmp', ...}) export class ComponentC { constructor(private vehicleService:VehicleService) {} saveVehicle(vehicle) { this.vehicleService.updateVehicle(vehicle); } }
It just shows the basics, but full functionality will be the way SO's broad answer is.
https://github.com/ngrx/store can be interesting for your use case, which simplifies the centralized management of all updates.