require: 'prDef'
works when prAbc
and prDef
are applied on the same DOM element, which is not your case.
What you may need is "parent" directive which will act as a router between the two communicating directives. prDef
registers itself to the parent controller and prAbc
calls the parent controller which, in turn, calls prDef
.
Check out this plucker.
There are at least 3 other options to consider:
Have the parent controller listen to specific events that
prAbc
emits and broadcasts them downwards, whereprDef
listens on.Have the parent controller pass callback functions (
'&'
) to the child directives for registration and routing.All functions and data is defined on the parent and passed to child directives through binding or prototypal inheritance (essentially, ruin your design :P).
For all 3 options, the parent controller does not have to be defined in a directive, it can be any controller which you apply like:
<div ng-contoller="ParentCtrl">
<pr-abc></pr-abc>
<pr-def></pr-def>
</div>
Your example does not provide enough context to reason which option is the best, but I think the parent directive should be the preferred way to go.
If it helps, checkout how ui-bootstrap's tabs and accordion are implemented. It's a very helpfull example of collaborating, still decoupled, set of directives.