I'm writing a script to populate my app database with Dummy Data as I am getting tired of manually adding users/friends/etc, I'm doing this by nesting AngularJS $http requests that speak to my app backend API/Rest service...
So far all is working well but now I need to loop async calls, like so... please note that this is the 3rd nested $http call
// 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
}
I'm currently getting the following error...
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 slight amends to my code but nothing seems to work, I assume my approach is wrong rather than the code (but I could be wrong there). Has anyone got an idea or recomendation on how i can overcome this issue?
$httpwithin ()?