I would like to implement promises in my AngularJS application like you can see in this example: https://stackoverflow.com/a/12360882/371273
My application will take multiple arrays of data making multiple database hits on my server, but I have configured my server to return all of that data as one response in the idea of minimizing requests to keep my application as efficient as possible (the data is essentially useless unless all of the data gets to the client). So instead of doing this...
MyCtrl.resolve = {
projects : function($q, $http) {
return $http.get('/api/projects'});
},
clients : function($q, $http) {
return $http.get('/api/clients'});
}
};
I would like to be able to make a single $http
GET request to a URL like /api/allData
, and then have a promise for projects
that will be set equal to allData.projects
and a promise for clients
that will be set equal to allData.clients
, etc. (where allData
is the data that came back with my single request). I'm still very new to promises, can someone give me an example of how I would set up these promises inside MyCtrl.resolve
?