December 2014
Intermediate to advanced
346 pages
6h 14m
English
AngularJS provides a useful structure that allows you to build channels of communication between directive siblings (within the same HTML element) or parents in the same DOM ancestry without having to rely on AngularJS events.
For this recipe, suppose that your application template includes the following:
(index.html)
<div ng-app="myApp">
<div parent-directive>
<div child-directive
sibling-directive>
</div>
</div>
</div>Inter-directive communication is accomplished with the require attribute, as follows:
return {
require: ['^parentDirective', '^siblingDirective'],
link: function (scope, el, attrs, ctrls) {
$log.log(ctrls);
// logs array of in-order required controller objects
}
};Using ...
Read now
Unlock full access