The common scenario of requiring a parent controller in a child directive shown here:
the Client directive requires the parent Server controller
<div server>
<div client></div>
</div>
var app = angular.module("app", []);
app.directive("server", function() {
return {
controller: function() {
this.log = function(message) {
console.log(message);
};
}
};
});
app.directive("client", function() {
return {
require: "^server",
link: function($scope, $elem, $attrs, serverCtrl) {
serverCtrl.log("Hello, this is the client!");
}
};
});
What if I have a third directive directive called MegaServer
app.directive("MegaServer", function() {
return {
controller: function() {
this.log = function(message) {
console.log(message);
};
}
};
});
MegaServer can also be a parent to "Client".
<div server>
<div client></div>
</div>
<div mega-server>
<div client></div>
</div>
How do I define my Client directive to require the parent controller if it can be of type either Server or MegaServer?