Skip to content

Commit 7df7d1a

Browse files
James Kleehpetebacondarwin
James Kleeh
authored andcommitted
docs(guide/directive): explain how to require multiple controllers
Closes angular#8524
1 parent fcd76d2 commit 7df7d1a

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

docs/content/guide/directive.ngdoc

+24
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,30 @@ Looking back at `myPane`'s definition, notice the last argument in its `link` fu
909909
When a directive requires a controller, it receives that controller as the fourth argument of its
910910
`link` function. Taking advantage of this, `myPane` can call the `addPane` function of `myTabs`.
911911

912+
If multiple controllers are required, the `require` option of the directive can take an array argument.
913+
The corresponding parameter being sent to the `link` function will also be an array.
914+
915+
```js
916+
angular.module('docsTabsExample', [])
917+
.directive('myPane', function() {
918+
return {
919+
require: ['^myTabs', '^ngModel'],
920+
restrict: 'E',
921+
transclude: true,
922+
scope: {
923+
title: '@'
924+
},
925+
link: function(scope, element, attrs, controllers) {
926+
var tabsCtrl = controllers[0],
927+
modelCtrl = controllers[1];
928+
929+
tabsCtrl.addPane(scope);
930+
},
931+
templateUrl: 'my-pane.html'
932+
};
933+
});
934+
```
935+
912936
Savvy readers may be wondering what the difference is between `link` and `controller`.
913937
The basic difference is that `controller` can expose an API, and `link` functions can interact with
914938
controllers using `require`.

0 commit comments

Comments
 (0)