title: defer.promise returning same result for simultaneous calls with different data inputs in angularJS
body: <p>I have a factory which does a JavaScript remoting to my salesforce apex class and return promises. I'm making call to a factory method multiple times simultaneously which will return me defer.promise for each call. But somehow its always returning me result of first call every time. Even though my response from server is different inside factory method during defer.resolve(response), when returning defer.promise its returning the same result every time to controller. I tried debugging but couldn't find any success. could anyone suggest what am I doing wrong.</p>
  
  <p>Here is my factory method:</p>
  
  <pre><code>app.factory('FieldSetFactory', ['$q', '$log', function($q, $log) {
  
  var fieldSet = {};
  var defer = $q.defer();
  
  fieldSet.getFields = function(scope,fieldSetName, objectName) { 
      this.scope = scope;
      var self = this;
  
      FieldSetController.getFieldSetInfo(fieldSetName,objectName,function(response, event) {
          if(event.status) {
              console.log('response =',response);  //this prints the actual result returned from server for different calls with different parameters
              defer.resolve(response);     
          } 
          else {
              $log.error(event.message);
              defer.reject(event.message);
          } 
  
      }); 
  
      return defer.promise;
  }
  
  return fieldSet;
  
  }]);
  </code></pre>
  
  <p>I have kept my contoller name as fieldSetJsController{!cid} where {!cid} is unique and passed by any component which is trying to use it.This is to make controller scope to individual calls and not overwriting same everytime, some other component passed some data. </p>
  
  <pre><code>app.controller('fieldSetJsController{!cid}', ['$scope', 'dataService',     
  'requestNotificationChannel','FieldSetFactory', function($scope, 
  
   dataService,  
   requestNotificationChannel,FieldSetFactory) {
  
  
   FieldSetFactory.getFields($scope,$scope.fieldSetName,$scope.objectAPIName).then(function(response){
          console.log("response in controller..............",response);  //this response always shows reslut of first call and any subsequent calls return same defer.promise
          $scope.fieldsetList = JSON.parse(response.replace(/&amp;/g,'').replace(/quot;/g,'"'));
          console.log("FiledSets..............",$scope.fieldsetList);  //this is always printing same result for different calls with different parameter
      });
  
   }]);
  </code></pre>
  
  <p>These are my components which are calling same controller with different {!cid} value to differentiate them.</p>
  
  <pre><code>&lt;c:FieldSetComponent objectAPIName="Applications__c" 
   fieldSet="Application_FieldSet_One" cid="Applications_FieldSet_One" 
                   sectionTitle="Section 1" columns="2" textAlign="center"&gt;
   &lt;/c:FieldSetComponent&gt;
  
   &lt;c:FieldSetComponent objectAPIName="Applications__c" 
   fieldSet="Application_FieldSet_Second" cid="Applications_FieldSet_Second" 
                   sectionTitle="Section 2" columns="2" textAlign="center"&gt;
   &lt;/c:FieldSetComponent&gt;
  &lt;c:FieldSetComponent objectAPIName="clcommon__Collateral__c"   
  fieldSet="Collateral_FieldSet_One" cid="Collateral_FieldSet_One" 
                   sectionTitle="Section 3" columns="2" textAlign="center"&gt;
  &lt;/c:FieldSetComponent&gt;
  </code></pre>