From e6e88119effe4fd57421997319d18bac87758ee4 Mon Sep 17 00:00:00 2001 From: Michael Salmon Date: Tue, 6 Oct 2015 15:28:59 -0700 Subject: [PATCH 1/4] docs(guide/Directives): describe your change... The 4th param for link() was not defined in the api doc, but used in the examples. This change adds the param and describes it. --- docs/content/guide/directive.ngdoc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/content/guide/directive.ngdoc b/docs/content/guide/directive.ngdoc index 47c38d5fb450..55315fa950c5 100644 --- a/docs/content/guide/directive.ngdoc +++ b/docs/content/guide/directive.ngdoc @@ -588,13 +588,14 @@ In this example we will build a directive that displays the current time. Once a second, it updates the DOM to reflect the current time. Directives that want to modify the DOM typically use the `link` option. -`link` takes a function with the following signature, `function link(scope, element, attrs) { ... }` +`link` takes a function with the following signature, `function link(scope, element, attrs, controller) { ... }` where: * `scope` is an Angular scope object. * `element` is the jqLite-wrapped element that this directive matches. * `attrs` is a hash object with key-value pairs of normalized attribute names and their corresponding attribute values. +* `controller` is the controller for the directive, if defined In our `link` function, we want to update the displayed time once a second, or whenever a user changes the time formatting string that our directive binds to. We will use the `$interval` service From 33d8a27fb2693a964d30ecdd9ae379f6f69087a2 Mon Sep 17 00:00:00 2001 From: Michael Salmon Date: Wed, 7 Oct 2015 14:43:01 -0700 Subject: [PATCH 2/4] docs(guide/Directives): Adds reference to $compile for link function parameters and gives quick intro to 5th param transcludeFn which was also missing in doc. --- docs/content/guide/directive.ngdoc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/content/guide/directive.ngdoc b/docs/content/guide/directive.ngdoc index 55315fa950c5..7d42d28c45ee 100644 --- a/docs/content/guide/directive.ngdoc +++ b/docs/content/guide/directive.ngdoc @@ -587,15 +587,15 @@ want to reuse throughout your app. In this example we will build a directive that displays the current time. Once a second, it updates the DOM to reflect the current time. -Directives that want to modify the DOM typically use the `link` option. -`link` takes a function with the following signature, `function link(scope, element, attrs, controller) { ... }` -where: +Directives that want to modify the DOM typically use the `link` option, which is documented on the {@link ng.$compile `$compile` API} page. +`link` takes a function with the following signature, `function link(scope, element, attrs, controller, transcludeFn) { ... }`, where: * `scope` is an Angular scope object. * `element` is the jqLite-wrapped element that this directive matches. * `attrs` is a hash object with key-value pairs of normalized attribute names and their corresponding attribute values. -* `controller` is the controller for the directive, if defined +* `controller` is the controller for the directive, if defined. +* `transcludeFn` is a transclude linking function pre-bound to the correct translusion scope. In our `link` function, we want to update the displayed time once a second, or whenever a user changes the time formatting string that our directive binds to. We will use the `$interval` service @@ -998,7 +998,7 @@ angular.module('docsTabsExample', []) scope: { title: '@' }, - link: function(scope, element, attrs, controllers) { + link: function(scope, element, attrs, controllers, transcludeFn) { var tabsCtrl = controllers[0], modelCtrl = controllers[1]; From b950c752a44580552431df3a0fba40e1533da6f2 Mon Sep 17 00:00:00 2001 From: Michael Salmon Date: Sat, 10 Oct 2015 13:24:25 -0700 Subject: [PATCH 3/4] docs(guide/Directives): Updates high level overview for directive link function based on PR comments --- docs/content/guide/directive.ngdoc | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/docs/content/guide/directive.ngdoc b/docs/content/guide/directive.ngdoc index 7d42d28c45ee..ccfa05fe385a 100644 --- a/docs/content/guide/directive.ngdoc +++ b/docs/content/guide/directive.ngdoc @@ -587,15 +587,24 @@ want to reuse throughout your app. In this example we will build a directive that displays the current time. Once a second, it updates the DOM to reflect the current time. -Directives that want to modify the DOM typically use the `link` option, which is documented on the {@link ng.$compile `$compile` API} page. -`link` takes a function with the following signature, `function link(scope, element, attrs, controller, transcludeFn) { ... }`, where: +Directives that want to modify the DOM typically use the `link` option to register DOM listeners +as well as update the DOM. It is executed after the template has been cloned and is where +directive logic will be put. + + `link` takes a function with the following signature, +`function link(scope, element, attrs, controller, transcludeFn) { ... }`, where: * `scope` is an Angular scope object. * `element` is the jqLite-wrapped element that this directive matches. * `attrs` is a hash object with key-value pairs of normalized attribute names and their corresponding attribute values. -* `controller` is the controller for the directive, if defined. -* `transcludeFn` is a transclude linking function pre-bound to the correct translusion scope. +* `controller` is the directive's required controller instance(s) or it's own controller (if any). + The exact value depends on the directive's require property. +* `transcludeFn` is a transclude linking function pre-bound to the correct transclusion scope. + +
+For full detail on the `link` method refer to the {@link ng.$compile `$compile` API} page. +
In our `link` function, we want to update the displayed time once a second, or whenever a user changes the time formatting string that our directive binds to. We will use the `$interval` service From 7eecf1a5b4228bb0ec4d7371f106de2cd11da384 Mon Sep 17 00:00:00 2001 From: Michael Salmon Date: Sat, 10 Oct 2015 17:08:23 -0700 Subject: [PATCH 4/4] docs(guide/Directives): link direct to $compile#-link- --- 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 ccfa05fe385a..328485f5f58f 100644 --- a/docs/content/guide/directive.ngdoc +++ b/docs/content/guide/directive.ngdoc @@ -603,7 +603,7 @@ directive logic will be put. * `transcludeFn` is a transclude linking function pre-bound to the correct transclusion scope.
-For full detail on the `link` method refer to the {@link ng.$compile `$compile` API} page. +For full detail on the `link` method refer to the {@link ng.$compile#-link- `$compile` API} page.
In our `link` function, we want to update the displayed time once a second, or whenever a user