If I have two directives, and need to have one of them use the controller of the other one, what is the best way to accomplish something like that in angular? I'm trying to use the require: otherDirective
stuff I see in the docs, but I'm getting an
Error: No controller: dirOne
from the following example. I was under the impression that by specifying dirOne in the require statement, dirTwo would have access to the controller of dirOne. What am I doing wrong here?
var app = angular.module('myApp', []); app.directive('dirOne', function() { return { controller: function($scope) { $scope.options = { "opt1" : true, "opt2" : false, "opt3" : false, } this.getOptions = function() { return $scope.options; }; } }; }); app.directive('dirTwo',function() { return { require: 'dirOne', link: function(scope, element, attrs, dirOneCtrl) { $scope.options = dirOneCtrl.getOptions(); alert($scope.options); } }; });