Posts

Showing posts from September, 2015

Promise Sharing in AngularJS

The Problem As any software project's complexity increases, separation of concerns becomes more and more important for overall maintainability. Angular services are a great way for multiple controllers to share functionality, and promotes the kind of decoupling that leads to clean, maintainable code. Although Angular services can really do anything, one of the more common uses of Angular services is to reach out to your server (via $http) and get some data. This is a great way to separate data-fetching logic from the business logic of your web application. However, this can also be a problem as your application becomes large. Let's say your application has multiple subviews, each with its own controller. These controllers know nothing about each other (since you're a good architect), and each has a dependency on the same Angular service to fetch some data from the same API endpoint. This results in two service calls to the server, each requesting the same data. For