Currently, I am in the process of automating the population of my app's database with Dummy Data to eliminate the manual task of adding users, friends, and more. To achieve this, I have implemented nested AngularJS $http requests that interact with my backend API/Rest service...
Everything has been functioning correctly up to this point, but now I face the challenge of looping asynchronous calls, like the example below where the 3rd nested $http call is illustrated.
// 3. Create Auto Friend For that User
for (var i = 1; i < 6; i++) { // 6 is just a given number, it could be 1 or 100....
($http({method: 'POST', url: '/path/to/rest/friend', data: {"name":"Auto Friend " + i}})
.then(function (response) {
console.log("friend created");
console.log(response);
}, function () {
console.log('Whoops...');
}))(i); // THIS IS LINE 69
}
However, I've encountered an error message...
TypeError: object is not a function
at http://localhost:9000/assets/js/src/app/auth/controllers/AuthCtrl.js:69:40
at wrappedCallback (http://localhost:9000/assets/js/vendor/bower/angular/angular.js:10549:81)
at http://localhost:9000/assets/js/vendor/bower/angular/angular.js:10635:26
at Scope.$eval (http://localhost:9000/assets/js/vendor/bower/angular/angular.js:11528:28)
at Scope.$digest (http://localhost:9000/assets/js/vendor/bower/angular/angular.js:11373:31)
at Scope.$delegate.__proto__.$digest (<anonymous>:844:31)
at Scope.$apply (http://localhost:9000/assets/js/vendor/bower/angular/angular.js:11634:24)
at Scope.$delegate.__proto__.$apply (<anonymous>:855:30)
at done (http://localhost:9000/assets/js/vendor/bower/angular/angular.js:7635:45)
at completeRequest (http://localhost:9000/assets/js/vendor/bower/angular/angular.js:7801:7)
I've made some adjustments to my code without success so far. It seems like my approach might be flawed rather than the code itself. If anyone has any suggestions or recommendations on how to resolve this issue, please share your thoughts!