Skip to content Skip to sidebar Skip to footer

How Can I Call The Second Sequential Promise Design Pattern Method In A Loop In Angularjs?

New to angularjs and trying out the promise pattern for the first time - I have a service utility inside which I have this method - this.getData= function(url){ var defer

Solution 1:

The issue is all in function closures. When the get data returns, your currentType is the last one because the for j loop ended already. So what you need to do is move the code starting from utility.getData to a separate method passing the parameters of the currentType and the seccondAttributeArray so the closure will contain them as parameters of the function and not change them as the for j loop progresses.

for (i = 0; i < $scope.myObjectArray.length; i++) { 
  var secondAttributeArray = []; 
  var currentType = $scope.myObjectArray[i];
  fillSecondAttributeArray($scope, secondAttributeArray, currentType);
 }

Post a Comment for "How Can I Call The Second Sequential Promise Design Pattern Method In A Loop In Angularjs?"