I'm trying to use the $q service to resolve multiple promises using the $q.all() function with AngularUI router but for some reasons this fails or it's not working as expected.
This is part of my configuration file that contains 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'
}
}
});
And this is the resolveHomeTeam function located 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);
}
As you can see in this case I'm pushing just one promise into the array and I know for sure that it's being resolved.
Since the only promise is resolved, shouldn't also the promise returned by $q.all() resolved? And shouldn't promiseData data be injected into the SegmentHomeTeamCtrl controller?
If I try to output promiseData inside SegmentHomeTeamCtrl controller I get the whole promise back containing also the actual data returned by the server buy for some reasons I cannot access it.
UserService.team()? Does it return a promise?