I am attempting to utilize the $q
service to resolve multiple promises using the $q.all()
function with AngularUI router. However, I am encountering issues where it is failing or not functioning as expected.
This snippet is from my configuration file that includes the $stateProvider
:
.state('home.team',
{
url : '^/team',
views : {
'main' : {
templateUrl : ConfigProvider.path.views + '/segment/home/team.html',
controller : 'SegmentHomeTeamCtrl',
resolve : {
promiseData : function(ResolveService) { return ResolveService.resolveHomeTeam(); }
}
},
'subMenu' : {
templateUrl : ConfigProvider.path.views + '/menu/home/team.html'
}
}
});
Here is the resolveHomeTeam
function found in the Resolve
service:
function resolveHomeTeam()
{
var promises = [];
promises.push($q.defer());
UserService.team('me', function(data)
{
promises[0].resolve(data);
}, function()
{
promises[0].reject();
});
return $q.all(promises);
}
In this scenario, only one promise is being added to the array and it is known to be resolved.
If the single promise is resolved, shouldn't the promise returned by $q.all()
also be resolved? And should the data from promiseData
be injected into the SegmentHomeTeamCtrl
controller?
When trying to display promiseData
within the SegmentHomeTeamCtrl
controller, the entire promise is received back along with the actual server data, but there are difficulties in accessing it.