title: Angularjs: Store $resource data in service to share across controllers
body: <p>Short question: Is it possible to store the data from $resource in a service, so as to query once and use it in different controllers?</p>
  
  <p>I tried <code>query().$promise.then</code>, but still resource is returning an empty reference. What is the correct syntax to resolve and store the $resource data in a service, such that subsequent calls can make use of it?</p>
  
  <pre><code>factory('DataService', function($resource) {
      var resource = $resource("/api/data", {}, {
          query: { isArray: false }
      });
  
      var data;
      return {
          get: function (args) {
              if (!data) {
                  resource.query().$promise.then(
                      function(result) {
                          data = result.message;  
                          return data;
                      }
                  );  
              }
              return data;
          }
      }; 
  </code></pre>