That is to wait for an user to click one of repeated elements and to 
propagate the width of the element to main scope. That is a part of a code 
to wrap textarea height acordingly to text length. It is to work in 
realtion of a div of the same width that textarea.

Your advice, Eric, helped me a lot. So I prepared that: plnkr 
<http://plnkr.co/edit/DtmVrvcMNGMkX9ASZGlg?p=preview>

<!DOCTYPE html>
<html>
<body>
  <div ng-app="app" ng-controller="Main">
    <button ng-repeat = "abc in [0,1,55]" add2-mem-button>Mem 
{{abc}}</button>
    <button ng-click = "log()">Show</button>
  </div>
  <script src="https://code.angularjs.org/1.3.6/angular.js";></script>
  <script>
    console.clear();
    var app = angular.module('app', []);
    app.service('Mem', [function () {
      var service = {
        mem: function (fvr) {
          console.log('Mem '+ fvr);
          service.vr = fvr;
        }
      }
      return service;
    }]);
    var ctrl = ['$scope', 'Mem', function($scope, Mem) {
      $scope.log = function(){if(Mem.vr)console.log(Mem.vr)}
    }];
    app.controller ("Main", ctrl);
    var directives = {};
    directives.add2MemButton = ['Mem', function(Mem) {
        return {
          link: function(scope, element, attrs) {
            element.bind('click', function () {
              var str = element[0].textContent || element[0].innerText;
              Mem.mem(str.split(' ').pop());
            });
          }
        }
      }
    ];
    app.directive(directives);
  </script>
</body>
</html> 
 



W dniu środa, 17 grudnia 2014 20:49:11 UTC+1 użytkownik Eric Eslinger 
napisał:
>
> What are you actually trying to do? This kind of violates a scoping 
> separation issue- what if wi has different values based on different states 
> of each of the instantiated ng-repeat items?
>
> It seems like, if you want to do something with higher-level values 
> propagating up and down, the best thing to do is the standard one: create a 
> service object to store your value, inject it in both the give-wi and 
> higher scope, and use that to store the value. I'm still not sure I grok 
> what you're trying to accomplish, but that would do it.
>
> e
>
> On Wed Dec 17 2014 at 11:38:59 AM trzczy <[email protected] <javascript:>> 
> wrote:
>
>> plunker <http://plnkr.co/edit/Sxq0uQ4vAZhEVDxbudoE?p=preview>
>>
>> <!DOCTYPE html>
>> <html>
>> <body>
>>   <div ng-app="app" ng-controller="test">
>>     <i ng-repeat = "abc in [1,2,3]" give-w>abc<br></i>
>>     <br>{{ wi }}
>>     </div>
>>   <script src="https://code.angularjs.org/1.3.6/angular.js";></script>
>>   <script>
>>     console.clear();
>>     app = angular.module('app', []);
>>     app.controller('test', function($scope) {
>>     });
>>     var directives = {};
>>     directives.giveW = [
>>       function() {
>>         return {
>>           link: function(scope, element, attrs) {
>>             scope.wi = 5;
>>           }
>>         }
>>       }
>>     ];
>>     app.directive(directives);
>>   </script>
>> </body>
>> </html>
>>
>> The value of *wi* is present the child scope of *ng-repeat*. How to 
>> propagate it to its parent scope so it would be present in the main scope 
>> and in html view? When ng-repeat is removed the *wi* value of 5 is 
>> actually present in html view but *ng-repeat* must remain.
>>
>> How to do that? Thanks in advance
>>
>> -- 
>> 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] <javascript:>.
>> To post to this group, send email to [email protected] 
>> <javascript:>.
>> Visit this group at http://groups.google.com/group/angular.
>> For more options, visit https://groups.google.com/d/optout.
>>
>

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