I have almost managed it. Any suggestions and comments would be greatly 
appreciated.

Link to Plunker <http://plnkr.co/edit/fwFlHfoSGcVOo9fE68Zs?p=preview>


<!DOCTYPE html>
<html ng-app="plunker">

<head>
  <meta charset="utf-8" />
  <title>AngularJS Plunker</title>
  <script data-require="[email protected]" 
src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.7/angular.js"; 
data-semver="1.3.7"></script>
</head>

<body ng-controller="MainCtrl">
  <div defer-magic ng-repeat='a2 in [0,0,0,0,0,0,0] track by 
$index'>{{$index+1}}</div>
  <script>
    console.clear();
    var app = angular.module('plunker', []);
    app
      .controller('MainCtrl', ['$scope', '$q', '$timeout',
        function($scope, $q, $timeout) {
          $scope.list2 = [];
          $scope.fn = function() {
            var t0 = parseInt(Math.random() * 4000),
              el = $scope.list2[0].element2[0],
              val2 = el.childNodes[0].nodeValue;
            console.log(t0);
            el.childNodes[0].nodeValue = t0;
            el.style.backgroundColor = '#ddd';
            $scope.list2.shift().defer2.promise.then(function() {
              !$scope.list2[0] || $timeout(function() {
                $scope.list2[0].defer2.resolve();
                $scope.fn();
              }, t0)
            })
          }
        }
      ])
      .directive('deferMagic', ['$q', '$timeout',
        function($q, $timeout) {
          var dir2 = {
            link: function(s, e) {
              var deff2 = $q.defer();
              s.list2.push({
                element2: e,
                defer2: deff2
              });
              if (s.$last) {
                s.list2[0].defer2.resolve();
                s.fn();
              }
            }
          }
          return dir2
        }
      ]);
  </script>
</body>

</html>

Thank you

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to