0

If I have the following factories:

  .factory('User', function($resource) {
    return $resource('/users/:id', {id: "@id"}, {
      query: {method: 'GET', params: {}, isArray: false}
    });
  })

  .factory('UserList', function(User, $q) {
    var deferred = $q.defer();
    User.query({}, function(response) {
      deferred.resolve(response.data);
    });
    return deferred.promise;
  })

I know have a UserList that I can inject into all my controllers that need it. But, if I later in my application create a new user, how can I make the 'UserList'-factory "refresh"? Is there another approach that is (even) more "The Angular Way"?

kornfridge
  • 5,102
  • 6
  • 28
  • 40
  • Controllers are not singletons. Each time the view changes, its associated controller is instantiated, and the user list will thus be retrieved from the server. Or do I miss something? – JB Nizet Jul 24 '13 at 17:16
  • See http://stackoverflow.com/a/14337338/215945 – Mark Rajcok Jul 24 '13 at 18:48
  • @JBNizet - The controller will reload yes, but the ´UserList´ that is injected into the controller is the same. – kornfridge Jul 25 '13 at 08:46

0 Answers0