I'm looping through some items in AngularJS and asking user input on each item using an AngularUI modal. My problem is that the loop finishes and all the modals render at once, without waiting for the user.
How can I make execution wait until the modal is closed?
An example of my code:
var listofitems = somelist; // loop through each item for (var i in listofitems){ if (listofitems[i].id == presetId){ // ask user confirmation in a modal $scope.selections = {'doThis': doThis, 'doThat': doThat} var openModal = function () { var modalInstance = $modal.open({ templateUrl: 'confirmationModal.html', controller: confirmationController, resolve: { selections: function () { return $scope.selections; } } }); modalInstance.result.then(function (selections) { doThis = selections.doThis; if (selections.doThat){ doThis = selections.doThis; } }); } // open the modal openModal(); } } } var confirmationController = function ($scope, $modalInstance, selections) { $scope.selections = selections; $scope.doThis = function () { $scope.selections.doThis = true; $modalInstance.close($scope.selections); }; $scope.doThat = function () { $scope.selections.doThat = true; $modalInstance.close($scope.selections); }; }; Incorporating @dsfg answer here's a Plunkr example. The ui modals don't work that well, but you can see execution has finished before the user has submitted any input.