I want to make multiple requests where the data appends the title with a number. But instead of e.g. "Hello 1", "Hello 2", "Hello 3", "Hello 4" I get "Hello 4", "Hello 4", "Hello 4", "Hello 4".
console.log(item.title);
shows "Hello 1", "Hello 2", "Hello 3", "Hello 4" correctly in the console.
I am guessing that it is because the request are asynchronous.
vm.title = vm.case.title;
for (let i = 1; i <= vm.number_of_cases_to_create; i++) {
vm.createNewCase(i, vm.case);
}
function createNewCase(number, item) {
item.title = vm.title + ' ' + number;
console.log(item.title);
CaseProvider.create(item).then(function (case) {
console.log(case.id);
});
}