From c76700539b47953e03e08ae0002e46621e485be9 Mon Sep 17 00:00:00 2001 From: Michal Bendowski Date: Mon, 4 Nov 2013 14:24:18 +0000 Subject: [PATCH 1/2] Update directive.ngdoc The example about transclusion and scopes worked only because the order of scope and element arguments is reversed. To really work, the directive has to define its own scope (at least that's my understanding of it). --- docs/content/guide/directive.ngdoc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/content/guide/directive.ngdoc b/docs/content/guide/directive.ngdoc index d45cacd37167..e3547af5a9de 100644 --- a/docs/content/guide/directive.ngdoc +++ b/docs/content/guide/directive.ngdoc @@ -634,8 +634,9 @@ redefines `name` as `Jeff`. What do you think the `{{name}}` binding will resolv return { restrict: 'E', transclude: true, + scope: {}, templateUrl: 'my-dialog.html', - link: function (element, scope) { + link: function (scope, element) { scope.name = 'Jeff'; } }; @@ -659,6 +660,9 @@ The `transclude` option changes the way scopes are nested. It makes it so that t transcluded directive have whatever scope is outside the directive, rather than whatever scope is on the inside. In doing so, it gives the contents access to the outside scope. +Note that if the directive did not create its own scope, then `scope` in `scope.name = 'Jeff';` would +reference the outside scope and we would see `Jeff` in the output. + This behavior makes sense for a directive that wraps some content, because otherwise you'd have to pass in each model you wanted to use separately. If you have to pass in each model that you want to use, then you can't really have arbitrary contents, can you? From 255591be8da29f943b034d108bf794b4a65c3cf3 Mon Sep 17 00:00:00 2001 From: Michal Bendowski Date: Tue, 5 Nov 2013 09:41:26 +0000 Subject: [PATCH 2/2] Removed the 'element' argument from transclusion scopes example. --- 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 e3547af5a9de..566150566181 100644 --- a/docs/content/guide/directive.ngdoc +++ b/docs/content/guide/directive.ngdoc @@ -636,7 +636,7 @@ redefines `name` as `Jeff`. What do you think the `{{name}}` binding will resolv transclude: true, scope: {}, templateUrl: 'my-dialog.html', - link: function (scope, element) { + link: function (scope) { scope.name = 'Jeff'; } };