Title: ng-transclude should not create new sibling scope. · Issue #5489 · angular/angular.js · GitHub
Open Graph Title: ng-transclude should not create new sibling scope. · Issue #5489 · angular/angular.js
X Title: ng-transclude should not create new sibling scope. · Issue #5489 · angular/angular.js
Description: This is more of a change request and I would like to see what other people think. In my humble opinion ng-transclude should not create it's own scope or at least have a way to prevent it from doing so. The reason behind this is that a di...
Open Graph Description: This is more of a change request and I would like to see what other people think. In my humble opinion ng-transclude should not create it's own scope or at least have a way to prevent it from doing...
X Description: This is more of a change request and I would like to see what other people think. In my humble opinion ng-transclude should not create it's own scope or at least have a way to prevent it from d...
Mail addresses
notifications@github.com
Opengraph URL: https://github.com/angular/angular.js/issues/5489
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"ng-transclude should not create new sibling scope.","articleBody":"This is more of a change request and I would like to see what other people think.\n\nIn my humble opinion ng-transclude should not create it's own scope or at least have a way to prevent it from doing so. The reason behind this is that a directive which requests transclusion already has means to specify whether or not it wants to have a scope or an isolated scope or no scope at all. It uses ng-transclude directive to mark where it wants to insert the content. When ng-transclude creates it's own sibling scope it kind of breaks the expectations of the directive which defines what kind of scope it wants and there comes the manifestation of the popular 'value' vs 'object.value' confusion.\n\nHere's an example of where new scope doesn't make sense in my opinion:\n\n```\nui.directive('box', function() {\n return {\n restrict: 'E',\n transclude: true,\n template: '\u003cdiv ng-transclude/>',\n replace: true,\n scope: {}\n };\n});\n```\n\nAll this directive wants is replace the `\u003cbox>content\u003c/box>` with a `\u003cdiv>content\u003c/div>` and the content to have the isolated scope.\n\nCreating nested structure of directives like this leads to a scope tree pollution. Here's a plunker example (http://plnkr.co/edit/DwukVGGprFFjQuVY8yTz) of three nested directives which create a scope tree structure like this:\n\n```\n\u003c Scope (002) : ng-app\n \u003c Scope (003) : ng-controller\n \u003c Scope (004) : box\n \u003c Scope (005) : ng-transclude\n \u003c Scope (006) : box\n \u003c Scope (007) : ng-transclude\n \u003c Scope (008) : box\n \u003c Scope (009) : ng-transclude\n```\n\nThis behaviour doesn't seem to add any value to its purpose but creates a lot of confusion among beginners.\n\nAt the moment I use the following workaround which achieves exactly what the previous example does:\n\n```\nui.directive('box', function() {\n return {\n restrict: 'E',\n transclude: true,\n template: '\u003cdiv/>',\n replace: true,\n scope: {},\n link: function(scope, element, attrs, transclude) {\n transclude(scope.$parent, function(content) {\n element.append(content);\n });\n }\n };\n});\n```\n\nHere's a plunker example (http://plnkr.co/edit/46v6IBLkhS71L1WbUDFl) which illustrates this concept. It leaves the scope tree nice and tidy:\n\n```\n\u003c Scope (002) : ng-app\n \u003c Scope (003) : ng-controller\n \u003c Scope (004) : box\n \u003c Scope (005) : box\n \u003c Scope (006) : box\n```\n\nAnd the 2-way binding works the way many expect when they bind 'value' rather than 'object.value'. (I believe that the fact that passing just 'value' works in some cases but not the other and blaming the nature of prototypal inheritance in javascript is not a good excuse. The fact that many people find this behaviour unexpected indicates that there's an architectural flaw.)\n\nI would love to hear what other people think and use cases where they think that creating a new sibling scope for ng-transclude makes sense.\n","author":{"url":"https://github.com/mbykovskyy","@type":"Person","name":"mbykovskyy"},"datePublished":"2013-12-20T00:41:51Z","url":"https://github.com/angular/angular.js/issues/5489"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:ee162f55-af6e-1d5d-0af7-923958908f4c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A1B8:250F1:BCC3A:FFAD2:6AFE13AD |
| html-safe-nonce | a5f19a5199afdd65893d6e729d6d3897423c15aef22182a484011fc8094c9f34 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMUI4OjI1MEYxOkJDQzNBOkZGQUQyOjZBRkUxM0FEIiwidmlzaXRvcl9pZCI6IjgyMTUwNzA5MzA1MzE5MTQ2NjkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 7788e3c2f7872c8a05b3510cb74af38622e766b08729457f12c7e978633fcd22 |
| hovercard-subject-tag | issue:24598778 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular.js/5489/issue_layout |
| twitter:image | https://opengraph.githubassets.com/91c1298ad6e2d1d4fedf41e20646496ff3dc01757580d80556fb3cab2de9cde0/angular/angular.js/issues/5489 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/91c1298ad6e2d1d4fedf41e20646496ff3dc01757580d80556fb3cab2de9cde0/angular/angular.js/issues/5489 |
| og:image:alt | This is more of a change request and I would like to see what other people think. In my humble opinion ng-transclude should not create it's own scope or at least have a way to prevent it from doing... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mbykovskyy |
| hostname | github.com |
| expected-hostname | github.com |
| None | 3cd8a1d79ccbf9aecac62781f79072482a49047fb982b8c9e2ad4aca8bf6a9af |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular.js git https://github.com/angular/angular.js.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 460078 |
| octolytics-dimension-repository_nwo | angular/angular.js |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 460078 |
| octolytics-dimension-repository_network_root_nwo | angular/angular.js |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 05539640a34afe6142a519483d78ddd766a1304a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width