Reputation: 899
I have the following AngularJS fragment:
<div ng-controller="FooController as fooCtrl">
<bar-directive></bar-directive>
</div>
And the directive for bar-directive
looks something like:
angular.module("Foo").directive('barDirective', function() {
return {
restrict: 'E',
require: ['^FooController'],
link: function (scope, element, attrs, controllers) {
console.log(controllers);
}
};
});
I then get an error saying "Controller 'FooController', required by directive 'barDirective', can't be found". Can controllers not be inherited this way? Do I need to create a wrapper directive of my own?
Upvotes: 0
Views: 131
Reputation: 194
require is used to require another directive and inject its controller as the fourth argument to the linking function, you need to require ngController directive
require: ['^ngController'],
Upvotes: 1