title: Angular JS: Storing data on a promise
body: <p>My problem is that I don't know where to store data I need to access in the final callbacks for a http request. In jQuery I would just do the following</p>
  
  <pre><code>var token = $.get('/some-url', {}, someCallback);
  token.oSomeObject = {data: 'some data'};
  
  function someCallback( data, status, token ){
       token.oSomeObject.data // 'some data'
  }
  </code></pre>
  
  <p>I use the token to store request specific data.</p>
  
  <p>Now the only way I find to acheive the this in Angular is to store the data in the actual config:</p>
  
  <pre><code>var config = {
      url: '/some-url',
      method: 'GET',
      oSomeObject: { data: 'some data' }
  };
  $http(config).success(someCallback);
  
  function someCallback( data, status, headers, config ){
       config.oSomeObject.data // 'some data'
  }
  </code></pre>
  
  <p>For one this prevents you from using the short-hand calls ($http.get, $http.post) I also find it's much a much more obtrusive way when wrapping the calls in a specific service module. </p>
  
  <p>Is there any other way of doing this?</p>
  
  <h2>Updated to clarify</h2>
  
  <p>I'm probably just missing something simple here not understanding how to properly use the promise API, but just to be sure we're on the same page let me give you a bit more detail to the issue.</p>
  
  <p>I have 2 files: 1) Controller.js 2) AjaxServices.js (all ajax calls are defined here as methods on a service).</p>
  
  <p>AjaxServices.js looks like this:</p>
  
  <pre><code>app.service('AjaxService', function( $http ){
       var self = this;
  
       this.createUser = function( oUser, fSuccessCallback ){
            return $http.put('/api/user', {oUser: oUser})
                         .success(fSuccessCallback);
       }
  }
  </code></pre>
  
  <p>Controller.js looks like this:</p>
  
  <pre><code>app.controller('MyController', function( $scope, AjaxServices ){
       $scope.saveUser = function( oUser ){
            var oPromise = AjaxServices.createUser( oUser, $scope.onUserSaved );
  
            oPromise.oUser = oUser // this is how I solve it in jQuery.ajax. The oPromise
                                   // is then sent as the token object in the onUserSaved
                                   // callback
       }
       $scope.onUserSaved = function( oStatus, status, headers, config ){
            oStatus.id // here is the id of the newly created user 
                       // which I want to now hook on to the oUser local object
  
       }
  }
  </code></pre>
  
  <p>How would you achieve the same thing using the promise API?</p>