Returning A $promise From Two Resource Calls In Angularjs To Delay Route Change
Use Case Using a route provider, returning a $promise in the resolve will avoid the data popping up after the UI has loaded. However, I'm having trouble processing two different re
Solution 1:
You can use $q.all to return an array of promises
var resources = [];
resources.push(SingleResource.get({ id: $route.current.params.id }).$promise);
resources.push(ChildResource.get({ id: $route.current.params.id }).$promise);
return$q.all(resources) // You return an array of promises
Solution 2:
Try with like
resolve: {
parentResource: function($route, SingleResource) {
return SingleResource.get({ id: $route.current.params.id }).$promise;
},
childResources: function($route, ChildResource, parentResource) {
return (parentResource.length > 0) ? ChildResource.get({ id: $route.current.params.id }).$promise : [];
}
}
https://medium.com/opinionated-angularjs/a2fcbf874a1c
Post a Comment for "Returning A $promise From Two Resource Calls In Angularjs To Delay Route Change"