Answer the question
In order to leave comments, you need to log in
AngularJS, how to delegate events from parent directive to child directives with isolated scope for everyone?
In fact, the title of the question already explains the essence of the problem.
How to delegate events from the parent directive to the directives of the children with an isolated scope for everyone?
$timeout
a call when loading the parent component, but in a real application, even this did not work. Also tried, hang directiverestrict: 'A'
on the button, which, according to the condition, simulates a click when loading. It also works in the example, but in the application, the button is also a directive and it is very problematic and ugly to get the element on which you really need to simulate a click.
Answer the question
In order to leave comments, you need to log in
No communication from top to bottom of the component tree through events (and up too)
. This is an outdated mechanism.
Use the new component notation, one-way bindings, and $onChanges in the controller.
jsbin.com/yoxohemiji/1
This approach also prepares you for Angular2.
This can also be done by requiring the parentDirective controller in childrenDirective, registering childrenDirective delegate instances in some list of child components in parentDirective. Then, when certain events occur, parentDirective will pull the controllers of these delegates and events are not needed.
Read up on the compile/link loop.
You can execute your logic in the postLink function and everything will be ok:
link: {
post: function($scope, element, attrs) {
$scope.$broadcast('SOME_EVENT_NAME');
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question