O'Reilly logo
  • Patrick S thinks this is interesting:

This especially occurs when you have multiple views visible at the same time and each one needs to be notified when your service's data changes. A good example is the shopping cart in an e-commerce application. As the user adds items to the cart, the cart needs to update its display of the contents along with other services that might display shipping costs, order totals, and so on.

To handle such situations, you need to use a publish/subscribe design pattern to both handle notifying consumers when long-running methods complete and to notify all the views in your application when your service's data changes.


Cover of AngularJS Services


messaging design pattern - let client know when service methods are complete