Skip to content

Commit 0db20bf

Browse files
bendowskijamesdaily
authored andcommitted
docs(guide/directive): fix transclusion example
The example about transclusion and scopes worked only because the order of `scope` and `element` arguments is wrong, which means that the `name' property of the scope is not really being updated. To really work, the directive has to define its own scope, either a new child scope or, as is more common with transclusion, an isolated scope. Closes angular#4774
1 parent fb270d1 commit 0db20bf

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

docs/content/guide/directive.ngdoc

+5-1
Original file line numberDiff line numberDiff line change
@@ -634,8 +634,9 @@ redefines `name` as `Jeff`. What do you think the `{{name}}` binding will resolv
634634
return {
635635
restrict: 'E',
636636
transclude: true,
637+
scope: {},
637638
templateUrl: 'my-dialog.html',
638-
link: function (element, scope) {
639+
link: function (scope, element) {
639640
scope.name = 'Jeff';
640641
}
641642
};
@@ -659,6 +660,9 @@ The `transclude` option changes the way scopes are nested. It makes it so that t
659660
transcluded directive have whatever scope is outside the directive, rather than whatever scope is on
660661
the inside. In doing so, it gives the contents access to the outside scope.
661662

663+
Note that if the directive did not create its own scope, then `scope` in `scope.name = 'Jeff';` would
664+
reference the outside scope and we would see `Jeff` in the output.
665+
662666
This behavior makes sense for a directive that wraps some content, because otherwise you'd have to
663667
pass in each model you wanted to use separately. If you have to pass in each model that you want to
664668
use, then you can't really have arbitrary contents, can you?

0 commit comments

Comments
 (0)