Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.min.js"></script>
<meta charset=utf-8 />
<title>ng-click</title>
</head>
<body>
  
    <div ng-controller="TodoCrtl">
      <button ng-click='action()'>Action</button>
      <div ng-repeat='number in numbers'>
        {{number}}
      </div>
      
    </div>
</body>
</html>
 
function TodoCrtl($scope, $timeout, $q) {
  $scope.numbers = [];
  
  $scope.action = function () {
    var promises = [];
    for (var i=0;i < 10 ; i ++) {
      // This should only accept a 
      // function returning a promise
      promises.push(testAsync(i));
    }
    $scope.numbers = $q.all(promises);
  };
  
  // Actual async call function as 
  // it has timout
  function testAsync (index) {
    var deferred = $q.defer();
    $timeout(function(){
      deferred.resolve(index);
    }, 1000)
    return deferred.promise;
  }
}
        
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anuragCESpro
0viewers