I have a scenario where I need to load ngResources in my global/main controller and pause the execution of anything else until they are loaded, similar to how the resolve property works for routes. How can I achieve this?
// Implementing one-time actions in the "global" controller.
app.controller('FrontendCtrl', function($scope, authService, sessionService) {
// Checking if the user has a cookie and fetching info from the server to reinitiate the session
authService.updateUser();
$scope.$session = sessionService;
});
// Authorization service
app.factory('authService', function($q, Auth, Other, sessionService) {
// Retrieving user data from the server - consists of one main query followed by additional ones using ngResources
var updateUser = function() {
Auth.profile(null, function(data) {
if(data) {
$q.all({
foo: Other.foo({ user_id: data.id }),
bar: Other.bar({ user_id: data.id }),
})
.then(function(results) {
sessionService.user = _.merge(results, data);
});
}
});
};
});
// Issue in the view - loading delay affecting updateUser function
{{ $session.user.name }}