title: Pause execution while AngularUI modal is open
body: <p>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.</p>
  
  <p>How can I make execution wait until the modal is closed?</p>
  
  <p>An example of my code:</p>
  
  <pre><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);
      };
  };
  </code></pre>
  
  <p>Incorporating @dsfg answer here's a <a href="http://plnkr.co/edit/TOhClP?p=info" rel="nofollow">Plunkr example</a>. The ui modals don't work that well, but you can see execution has finished before the user has submitted any input.</p>