1

I want to bind a click event on every children from inside parent directive. I tried iterating through the element with angular.each but with no success

HTML

<parent-component>
      <div>First element</div>    
      <div>Second element</div>
</parent-component>

SCRIPTS

angular.module('demoApp')
.directive('parentComponent', function () {
    return {
        restrict: 'EA',
        scope: {},
        link: function (scope, element, attrs) {    
            angular.forEach(element[0].children, function (currentElement) {
                currentElement.bind('click', function () {
                    console.log('You clicked ', currentElement);
                })
            });
        }
    }
});
georgeawg
  • 48,608
  • 13
  • 72
  • 95
Lupexlol
  • 63
  • 7

0 Answers0