From d9a8c99397e0b4f4c37152f98c84b91369f16b7b Mon Sep 17 00:00:00 2001 From: James Kleeh Date: Thu, 7 Aug 2014 09:17:57 -0400 Subject: [PATCH 1/2] Directive require multiple controllers Documentation to include an example of requiring multiple controllers. --- docs/content/guide/directive.ngdoc | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/docs/content/guide/directive.ngdoc b/docs/content/guide/directive.ngdoc index c83215ade216..b7c1a3f1058b 100644 --- a/docs/content/guide/directive.ngdoc +++ b/docs/content/guide/directive.ngdoc @@ -909,6 +909,32 @@ Looking back at `myPane`'s definition, notice the last argument in its `link` fu When a directive requires a controller, it receives that controller as the fourth argument of its `link` function. Taking advantage of this, `myPane` can call the `addPane` function of `myTabs`. +If multiple controllers are required, the `require` option of the directive can take an array argument. The +corresponding paramater being sent to the `link` function will also be an array. + + + + angular.module('docsTabsExample', []) + .directive('myPane', function() { + return { + require: ['^myTabs', '^ngModel], + restrict: 'E', + transclude: true, + scope: { + title: '@' + }, + link: function(scope, element, attrs, controllers) { + var tabsCtrl = controllers[0], + modelCtrl = controllers[1]; + + tabsCtrl.addPane(scope); + }, + templateUrl: 'my-pane.html' + }; + }); + + + Savvy readers may be wondering what the difference is between `link` and `controller`. The basic difference is that `controller` can expose an API, and `link` functions can interact with controllers using `require`. From 4857816acb9723cc7e117182fb5bf0b3b6722f38 Mon Sep 17 00:00:00 2001 From: James Kleeh Date: Thu, 7 Aug 2014 09:19:01 -0400 Subject: [PATCH 2/2] Update directive.ngdoc --- docs/content/guide/directive.ngdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/content/guide/directive.ngdoc b/docs/content/guide/directive.ngdoc index b7c1a3f1058b..fda6fc8d89cd 100644 --- a/docs/content/guide/directive.ngdoc +++ b/docs/content/guide/directive.ngdoc @@ -917,7 +917,7 @@ corresponding paramater being sent to the `link` function will also be an array. angular.module('docsTabsExample', []) .directive('myPane', function() { return { - require: ['^myTabs', '^ngModel], + require: ['^myTabs', '^ngModel'], restrict: 'E', transclude: true, scope: {