I am a newbie at angular promises. I succesfully run some codes of the 
construction of $q.defer() --- promise.than() ---- resolve() but I got 
stuck when tried to chain promises that were declared inside directives. I 
have prepared the code that confuses me why promises doesn't wait for each 
other in the chain. I hope its a metter of a little thing. The code is 
below.

Thank you in advance.

demo: plnkr <<!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"> <a 
defer-magic ng-repeat='a2 in [0,0,0,0,0,0,0,] track by 
$index'>{{$index+1}}</a> <script> console.clear(); var app = 
angular.module('plunker', []); app .controller('MainCtrl', ['$scope', '$q', 
'$timeout', function($scope, $q, $timeout) { var i = 0; $scope.chain = 
$q.when(); } ]) .directive('deferMagic', ['$q', '$timeout', function($q, 
$timeout) { var dir2 = { link: function(s, e, a) { s.chain = 
s.chain.then(function() { $timeout(function() { 
console.log(e[0].childNodes[0].nodeValue); 
document.write(e[0].childNodes[0].nodeValue+'... '); return 
e[0].childNodes[0].nodeValue }, 2000) }); } } return dir2 } ]); </script> 
</body> </html>>

<!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">
  <a defer-magic ng-repeat='a2 in [0,0,0,0,0,0,0] track by 
$index'>{{$index+1}}</a> 
  <script>
    console.clear();
    var app = angular.module('plunker', []);
    app
      .controller('MainCtrl', ['$scope', '$q', '$timeout',
        function($scope, $q, $timeout) {
          var i = 0;
          $scope.chain = $q.when();
        }
      ])
      .directive('deferMagic', ['$q', '$timeout',
        function($q, $timeout) {
          var dir2 = {
            link: function(s, e, a) {
              s.chain = s.chain.then(function() {
                $timeout(function() {
                  console.log(e[0].childNodes[0].nodeValue);
                  document.write(e[0].childNodes[0].nodeValue+'... ');
                  return e[0].childNodes[0].nodeValue
                }, 2000)
              });
            }
          }
          return dir2
        }
      ]);
  </script>
</body>
</html>


-- 
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