-
Notifications
You must be signed in to change notification settings - Fork 27.4k
controller not injected to link function when require used #11903
Comments
The work around:
|
This is how things work (for some reason 😄). Namely, if the directive has a controller and doesn't specify a The solution is to also require the directive itself: .directive('foo', function fooDirective() {
return {
...
require: ['foo', 'ngModel'],
controller: FooCtrl,
link: fooPostLink,
};
function FooCtrl() {}
function fooPostLink(scope, elem, attrs, ctrls) {
var fooCtrl = ctrls[0];
var ngModelCtrl = ctrls[1];
...
}
}) |
From a quick look, the 1st situation (passing the directive's controller if there is no |
Yeah, we should document this. It's a bit confusing, if you not always require all controllers. But I'm pretty sure it says nowhere that the controllers get passed as extra fn arguments. |
That's the problem :) It says: |
You are right. I was thinking about this because this will never work. |
I have this tag:
and this directive:
Now if I remove
require: ngModel
the controller is injected to the linking function:Is it a bug?
The text was updated successfully, but these errors were encountered: