I'm facing a situation where I need to access multiple directive controller methods.
Usually, I can access a method from a parent directive using the require attribute like this:
require:"^parentDirective"
However, I also need to access a method within a separate directive (not a parent). The documentation suggests using an array of strings like this:
require:["^parentDirective","directiveTwo"]
Unfortunately, implementing this causes errors even though both directives have been successfully compiled into the DOM.
Am I overlooking something here?
Below is the code for my directive:
angular.module('testModule', ['parentModule'], function () {
}).directive('testDirective', function() {
return {
restrict: 'AE',
templateUrl: 'testTemplate.tpl.html',
scope: {
value1: "=",
value2: "="
},
require:['^parentDirective','otherDirective'],
controller: function($scope,$modal,socketConnection) {
if(case_x == true){
$scope.requiredController_1.ctrl1Func();
}
else if(case_x == false){
$scope.requiredController_2.ctrl2Func();
}
},
link: function(scope,element,attrs,requiredController_1,requiredController_2){
scope.requiredController_1 = requiredController_1;
scope.requiredController_2 = requiredController_2;
}
};
});