I have many components displaying single or multiple products provided by a service.
getProducts() {
return this.http.get('/api/products');
}
getProduct(id) {
return this.http.get('/api/product/'+id);
}
In some components, I can add new products or edit them using this service.
saveProduct(product) {
if(product._id) {
return this.http.put('/api/product/'+product._id, product);
}
return this.http.post('/api/product', product);
}
These components are displayed simultaneously but not directly connected to each other. So, whenever a change occurs, I need to notify all other components about this change.
I think observables are the way to go, but I'm not sure how to get started.
What is the right way to keep data maintained throughout my app?