Angular $q.all Demonstration

HTML

<div ng-app="myApp">{{status}}</div>

JavaScript

(function () {
    var app = angular.module("myApp", []);
    
    app.run(['$rootScope', '$q', '$timeout', 
             function ($rootScope, $q, $timeout) {
                 
                 var one = $q.defer();
                 var two = $q.defer();
                 var three = $q.defer();
                 var four = $q.defer();
                 
                 function success(data){
                     $rootScope.status = data;
                 }
                                           
                 $q.all([one.promise, two.promise, three.promise, four.promise]).then(function (data) {
                      $rootScope.status = data;
                  }, function (error) {
                    	$rootScope.status = error;
                  });
                 
                 one.promise.then(success);
                 two.promise.then(success);
                 three.promise.then(success);
 								 four.promise.then(success);
                 
                 $timeout(function(){
                     one.reject('one done - error ');
                 }, 2000);
                 
                 $timeout(function(){
                     two.reject('two done - error');
                 }, 3000);
                 
                  $timeout(function(){
                     three.resolve('three done');
                 }, 1000); 
                 
                 $timeout(function(){
                     four.reject('four done');
                 }, 4000);                
    }]);
})();