Let's say I have a site where every controller is going to rely on a 'User' object. So I create a user service for the controllers to use to get this data:
myApp.factory('UserService', function ($http) {
var user = { Id: 1, Name: 'Test' };
return {
User: user
};
});
Where my controllers then look like this:
myApp.controller('SearchController', function ($scope, UserService) {
$scope.User = UserService.User;
})
My question is, assuming now we need to pull in that data from a $http
call (where the returned data is then manipulated before handing off to the controllers) AND just about every controller is going to need this data (so having them each manipulate it doesn't make sense), how do I go about implementing this?
I'm going in circles with examples regarding promises so I'm confused as to the proper way of handling this. Ideally I just need a way to have this data resolved before any controllers/views are populated