Title: Content lifecycle on conditional transclusion · Issue #13059 · angular/angular · GitHub
Open Graph Title: Content lifecycle on conditional transclusion · Issue #13059 · angular/angular
X Title: Content lifecycle on conditional transclusion · Issue #13059 · angular/angular
Description: I'm submitting a ... [x] bug report Current behavior When you use conditional directive on
Open Graph Description: I'm submitting a ... [x] bug report Current behavior When you use conditional directive on
X Description: I'm submitting a ... [x] bug report Current behavior When you use conditional directive on <ng-content> content component are correctly added/removed to the DOM depending on the condition...
Opengraph URL: https://github.com/angular/angular/issues/13059
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Content lifecycle on conditional transclusion","articleBody":"\u003c!--\r\nIF YOU DON'T FILL OUT THE FOLLOWING INFORMATION WE MIGHT CLOSE YOUR ISSUE WITHOUT INVESTIGATING\r\n-->\r\n\r\n**I'm submitting a ...** \r\n```\r\n[x] bug report\r\n```\r\n\r\n**Current behavior**\r\nWhen you use conditional directive on `\u003cng-content>` content component are correctly added/removed to the DOM depending on the condition but they have weird lifecycle. They have the same lifecyle than the parent, meaning when they are removed from the DOM the component instance is kept and reuse when they are added again to the DOM.\r\n\r\n**Expected behavior**\r\nContent component should have their own lifecycle corresponding to the conditional. Instantiate when adding to the DOM and destroyed when removed from the DOM.\r\n\r\n**Minimal reproduction of the problem with instructions**\r\nComponent using transclusion like that : \r\n```ts\r\n@Component({\r\n selector: 'conditional-content'\r\n template: `\r\n \u003cng-content *ngIf=\"condition\">\u003c/ng-content>\r\n \u003cbutton (click)=\"condition = !condition\">toggle\u003c/button>\r\n `\r\n})\r\n```\r\n\r\nLet's say you do : \r\n\r\n```\r\n\u003cconditional-content>\r\n \u003csome-component>\u003c/some-component>\r\n\u003c/conditional-content>\r\n```\r\n\r\nthen `\u003csome-component>` will have the same lifecycle has `conditional-content`.\r\n\r\nPlunker example:\r\nhttps://plnkr.co/edit/KdyKG6qtiA9eoqxJOIep\r\n\r\n**What is the motivation / use case for changing the behavior?**\r\nWhen content component rely on `ElementRef` because it becomes null when component is removed from the DOM.\r\n\r\n* **Angular version:** 2.0.X\r\n2.X.X\r\n\r\n* **Browser:** [all]\r\n \r\n* **Language:** [all]\r\n","author":{"url":"https://github.com/ghetolay","@type":"Person","name":"ghetolay"},"datePublished":"2016-11-23T13:24:15Z","url":"https://github.com/angular/angular/issues/13059"}
| 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:0adf807d-6bd9-4455-94c8-1f254525d342 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E73C:F7C4C:211604C:2C45DEA:6B018CDC |
| html-safe-nonce | 8068f89ba936a2354cd1e958c5f9d8cd044b6fee26392aeb21ea310720cc76fb |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNzNDOkY3QzRDOjIxMTYwNEM6MkM0NURFQTo2QjAxOENEQyIsInZpc2l0b3JfaWQiOiI2MzQ5NDYzNTMzNzQyMjk2Mjg0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | e499d14261d91f621305426495f14a82412bc397cdcc89653b092b87ced7b3d9 |
| hovercard-subject-tag | issue:191269380 |
| 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/13059/issue_layout |
| twitter:image | https://opengraph.githubassets.com/650a9ed46922735f14d0c9f03e2d1104fe91af81216bff708e25c38bc4933a01/angular/angular/issues/13059 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/650a9ed46922735f14d0c9f03e2d1104fe91af81216bff708e25c38bc4933a01/angular/angular/issues/13059 |
| og:image:alt | I'm submitting a ... [x] bug report Current behavior When you use conditional directive on |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ghetolay |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular git https://github.com/angular/angular.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 24195339 |
| octolytics-dimension-repository_nwo | angular/angular |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24195339 |
| octolytics-dimension-repository_network_root_nwo | angular/angular |
| 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 | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width