We currently have two directives known as parent
and child
. Both of these directives come with controllers that house specific functionalities. In the case of the child
directive, there are a couple of ways to access controllers:
- We can access the
parent controller
using therequire
property (require: '^parent'
). This allows us to receive the parent controller as the fourth parameter in our link function with the value:function link(scope, elem, attrs, parentCtrl)
- We can also access the
child controller
directly, without the need for usingrequire
. In this scenario, the childController will be passed directly as the fourth parameter in the link function.
With that said, how can we reference both the child and parent controllers within the child
's link function? You can find an example of this question demonstrated in a Plunker here: http://plnkr.co/edit/WzU6iJgf2zLLApFHeiEG?p=preview