I have a logical issue.
I have an array of objects in localStorage. What I want to do is , for each of them effectively make an API call and then push the new item in localStorage and once everything is done then only route to a new component.
if(migrationName){
angular.forEach(JSON.parse($window.localStorage.selectedItems), function(item) {
var url = '/api/get_all_prices/'+item.details.id+'/us-1';
HttpWrapper.send(url,{"operation":'GET'}).then(function(pricingOptions){
item.selectedMapping = pricingOptions[0];
vm.selectedItems[type].push(item); // Store it in a variable first
$window.localStorage.setItem('selectedItems',JSON.stringify(item));
});
});
$rootRouter.navigate(["MigrationRecommendation"]); // Route once everything is done
}
I know this is wrong.
I am setting localStorage each time in the loop and also I am not handling once everything in the array is done then only route.
How can the logic be changed ?