A
A
Alexander Evgenievich2015-04-26 13:41:55
JavaScript
Alexander Evgenievich, 2015-04-26 13:41:55

How to access child elements in a directive?

Hello.
Actually a question: "How to get access to child elements in the directive?".
What is :

<div class="list" my-directive>
     <div class="item"></div>
     <div class="item"></div>
     <div class="item"></div>
</div>

angular.module('MyModule').directive('myDirective', function(){
     return {
          restrict : 'A',
          scope : {}, // В рабочей версии нужны будут параметры
          link : function(scope, el){
               console.dir(el.children()); //Возвращает div.directive-div из template
          },
          compile : function(){
               return {
                    pre : function preLink(scope, el){
                         console.dir(el.children()); // Возвращает div.directive-div
                    }
               };
          },
          template : '<div class="directive-div"></div>'
     };
});

And I would like to get a list of child divs div.item . What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2015-04-26
@banderos120

Well, you replace the entire node with a template.
If you want to keep the content - use transclude

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question