Thanks for the answer, Sander. So i will explain the idea.

This issue is a part of my project I currently run. In general, the project 
is to make textareas flexible that they will enlarge and shrink accordingly 
when the text will be typed in them.

The idea is that the user input element will be binded to a div. The div 
will be css-styled so it will be as wide as current textarea and heigh 
adequately as current amount of text.

So when there is much text the div will be high and when there is little 
text the div will be low.

When the user focuses one of textareas the binding to the div will be 
estavlished and previeus binding (if any) will be over so it must not be 
more then one textarea binded to the div.

I have managed the code of the part of the project described above and it 
worked.

But there is another thing i must resolve in that research. It is an issue 
of storing and restoring data that was filled by user. The data is stored 
in database.

When the page opens the blank form of the textareas will appear. Then the 
data from database will be filled to the textareas. Then each of the 
textareas will be shaped to adjust its height to the text amount. The way o 
shaping a height of each area will be the same as when the user would 
focusing the textarea but then it just will be the script to controll each 
textarea process.

So then in the code it must be provided the chain of jobs. Each job should 
deal with one textarea. The job should establish the data binding to the 
div, adjust the height of the textarea to the one of the div, end the 
binding and say to the next textarea: 'Now you are the one who can use the 
div to adjust his height'.

So then the defer will be the amount time of textarea height adjusting. The 
promise will be 'When I finish I will let you use that div'.  The resolve 
will be 'I have finished height adjusting'.

I am just trying to code such a chain of jobs for DOM elements that were 
created by ng-repeat. That chain needs an access to the dom elements. That 
access is via directive. Directives should comunicate each other to say "i 
have resolved" to the next. The comunication is via the scope of the main 
controller. So this is why I try to learn using promises.
 
Regards

W dniu wtorek, 30 grudnia 2014 16:12:51 UTC+1 użytkownik trzczy napisał:
>
> 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>
>
>
>

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