Reputation: 615
We have two directives, called parent
and child
. Both of them have controllers defined, which hold some functionality. For child
directive we can:
parent controller
with require
property (require: '^parent'
), thus receiving fourth parameter to our link function with its value: function link(scope, elem, attrs, parentCtrl)
child controller
: without using require
, fourth link parameter will be our childController.So the question is: how can we reference both child and parent controllers in child
's link function? Here's a plunker with the example: http://plnkr.co/edit/WzU6iJgf2zLLApFHeiEG?p=preview
Upvotes: 3
Views: 81
Reputation: 52847
You can pass an array to the 'require' property of your directive definition, which includes both your child directive, and your parent directive. The 4th parameter to your link function will be an array:
app.directive('childDirective', function() {
require: ['childDirective', '^parentDirective'],
link: function(scope, element, attr, ctrls) {
var childCtrl = ctrls[0];
var parentCtrl = ctrls[1];
...
}
});
Upvotes: 5