I'd like to know how would be a good way to store data in angular.js that will be accessed across the app from different controllers. I'm using restangular to access the data on the backend. I have my own services to access the data, something like this:
app.factory('models.user', function(Restangular) {
var users;
users = {};
return {
get: function(user_id) {
return users[user_id] || (users[user_id] = Restangular.one('users', user_id).get());
}
};
});
For all models I define a service to access it. Using this, from any place of the app when I call User.get(1)
I get the same model instance.
I'd like to find a better way to do so. What do you guys do in to keep the same instances in your Angular.js apps?