René's URL Explorer Experiment


Title: Projected content is not hidden when dynamically creating a component if there is nowhere to project the content yet · Issue #54881 · angular/angular · GitHub

Open Graph Title: Projected content is not hidden when dynamically creating a component if there is nowhere to project the content yet · Issue #54881 · angular/angular

X Title: Projected content is not hidden when dynamically creating a component if there is nowhere to project the content yet · Issue #54881 · angular/angular

Description: Which @angular/* package(s) are the source of the bug? core Is this a regression? No Description When creating a component dynamically via ViewContainerRef.createComponent(), any content children created via ViewContainerRef.createEmbedd...

Open Graph Description: Which @angular/* package(s) are the source of the bug? core Is this a regression? No Description When creating a component dynamically via ViewContainerRef.createComponent(), any content children c...

X Description: Which @angular/* package(s) are the source of the bug? core Is this a regression? No Description When creating a component dynamically via ViewContainerRef.createComponent(), any content children c...

Opengraph URL: https://github.com/angular/angular/issues/54881

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Projected content is not hidden when dynamically creating a component if there is nowhere to project the content yet","articleBody":"### Which @angular/* package(s) are the source of the bug?\r\n\r\ncore\r\n\r\n### Is this a regression?\r\n\r\nNo\r\n\r\n### Description\r\n\r\nWhen creating a component dynamically via `ViewContainerRef.createComponent()`, any content children created via `ViewContainerRef.createEmbeddedView()` and provided through `options.projectableContent` are not detached from the document if the dynamically created component does not have a location to project content to yet. Instead, they remain attached to the document outside of the component they were supposed to be projected into. If this is not the intended way to do this, please correct me, but this was the only way I found to data bind the embedded view to the component its template was declared in.\r\n\r\n\r\n```ts\r\nfunction render\u003cC>(\r\n  componentType: Type\u003cC>,\r\n  viewContainerRef: ViewContainerRef,\r\n  templateRef: TemplateRef\u003cany>\r\n): void {\r\n  const embeddedViewRef = viewContainerRef.createEmbeddedView(templateRef);\r\n  viewContainerRef.createComponent(componentType, {\r\n    projectableNodes: [embeddedViewRef.rootNodes],\r\n  });\r\n}\r\n```\r\n\r\nThis situation arises with components that don't project content, or conditionally project content. For components with conditionally projected content specifically, once there is a location to project the content, the content will be moved there. If that location becomes unavailable again later, the projected content is properly detached from the document.\r\n\r\n![image](https://github.com/angular/angular/assets/111467777/4d3812df-4a93-4fd8-8f9c-8c3a938157ac)\r\n\r\nI expect projecting content in dynamically created components to be consistent with projecting content declaratively, which will always detach the content to project from the document if there is nowhere to project it. If this inconsistency is intentional, then I expect there to be a documented solution for replicating the behavior of projecting content declaratively when dynamically creating a component.\r\n\r\n### Please provide a link to a minimal reproduction of the bug\r\n\r\nhttps://stackblitz.com/edit/projected-content-not-hidden-dynamic-components?file=src%2Fapp%2Fapp.component.html\r\n\r\n### Please provide the exception or error you saw\r\n\r\nN/A. No errors in console.\r\n\r\n### Please provide the environment you discovered this bug in (run `ng version`)\r\n\r\n```true\r\nAngular CLI: 16.2.12\r\nNode: 16.20.2\r\nPackage Manager: npm 9.8.1\r\nOS: win32 x64\r\n\r\nAngular: 16.2.12\r\n... animations, cli, common, compiler, compiler-cli, core, forms\r\n... platform-browser, platform-browser-dynamic, router\r\n\r\nPackage                         Version\r\n---------------------------------------------------------\r\n@angular-devkit/architect       0.1602.12\r\n@angular-devkit/build-angular   16.2.0\r\n@angular-devkit/core            16.2.12\r\n@angular-devkit/schematics      16.2.12\r\n@angular/cdk                    16.2.14\r\n@angular/material               16.2.14\r\n@schematics/angular             16.2.12\r\nrxjs                            7.8.1\r\ntypescript                      5.1.6\r\nzone.js                         0.13.3\r\n```\r\n\r\n\r\n### Anything else?\r\n\r\nThere is a single workaround for both the no projectable content and conditionally projectable content cases, which is to use `Renderer2` to manually detach the elements created in the embedded view from the document before providing them to the component. I have provided examples of this workaround in the linked StackBlitz.\r\n\r\n```ts\r\nfunction renderWorkaround\u003cC>(\r\n  componentType: Type\u003cC>,\r\n  viewContainerRef: ViewContainerRef,\r\n  templateRef: TemplateRef\u003cany>,\r\n  renderer: Renderer2\r\n): void {\r\n  const embeddedViewRef = viewContainerRef.createEmbeddedView(templateRef);\r\n  for (const node of embeddedViewRef.rootNodes) {\r\n    renderer.removeChild(node.parentNode, node);\r\n  }\r\n  viewContainerRef.createComponent(componentType, {\r\n    projectableNodes: [embeddedViewRef.rootNodes],\r\n  });\r\n}\r\n```\r\n\r\n![image](https://github.com/angular/angular/assets/111467777/323b9a4c-8225-4285-9a28-6d46052b44b9)\r\n\r\nI am aware that this issue could theoretically be solved by [using the suggested alternative to `\u003cng-content>` for conditional content projection](https://angular.io/guide/content-projection#conditional-content-projection), but my attempted solution of passing `TemplateRef.element.nativeElement` (which is just a comment) in `options.projectableNodes` when creating the component that projects content would not let me retrieve the `TemplateRef` via `@ContentChild` later.\r\n\r\nI discovered this issue while implementing the [longstanding workaround](https://github.com/angular/components/issues/13784#issuecomment-440137435) for [cdkDragHandle being ignored when it is placed inside a child component](https://github.com/angular/components/issues/13784) for my dynamically created components. I figure it is worth mentioning as that issue was closed without an official solution over 5 years ago on the basis that it was not possible at the time. It might be worth revisiting if it is possible now.","author":{"url":"https://github.com/nolan-white","@type":"Person","name":"nolan-white"},"datePublished":"2024-03-15T16:01:32Z","url":"https://github.com/angular/angular/issues/54881"}

react-profiling0
react-import-mapreact,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-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:42aadb74-e7cf-a9dd-a50d-da955fc0f509
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idBA22:237673:146B91C:1B43293:6B0130F8
html-safe-nonceb8e67a49dabe9cfaeae4ed281ccb74349677b5044e4fa5bedc271e95a92da231
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQTIyOjIzNzY3MzoxNDZCOTFDOjFCNDMyOTM6NkIwMTMwRjgiLCJ2aXNpdG9yX2lkIjoiNDYyODMwMTMwMzA3MDY2NzAwMSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmaccfda100a228aa45243442844db7d34763a91a9d691b2a2482c7897dc231f72b9
hovercard-subject-tagissue:2188970155
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular/54881/issue_layout
twitter:imagehttps://opengraph.githubassets.com/c425c72cee05c14f8fa3b6afeceeaf32513199453c95676cdc064b59de968560/angular/angular/issues/54881
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/c425c72cee05c14f8fa3b6afeceeaf32513199453c95676cdc064b59de968560/angular/angular/issues/54881
og:image:altWhich @angular/* package(s) are the source of the bug? core Is this a regression? No Description When creating a component dynamically via ViewContainerRef.createComponent(), any content children c...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamenolan-white
hostnamegithub.com
expected-hostnamegithub.com
Nonecc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c
turbo-cache-controlno-preview
go-importgithub.com/angular/angular git https://github.com/angular/angular.git
octolytics-dimension-user_id139426
octolytics-dimension-user_loginangular
octolytics-dimension-repository_id24195339
octolytics-dimension-repository_nwoangular/angular
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id24195339
octolytics-dimension-repository_network_root_nwoangular/angular
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release8c77c9e8439031ad54c75a250694842892f693e1
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/angular/angular/issues/54881#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fangular%2Fangular%2Fissues%2F54881
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fangular%2Fangular%2Fissues%2F54881
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=angular%2Fangular
Reloadhttps://github.com/angular/angular/issues/54881
Reloadhttps://github.com/angular/angular/issues/54881
Reloadhttps://github.com/angular/angular/issues/54881
angularhttps://github.com/angular
angularhttps://github.com/angular/angular
Codehttps://github.com/angular/angular
Issues836 (836)https://github.com/angular/angular/issues
Pull requests141 (141)https://github.com/angular/angular/pulls
Discussionshttps://github.com/angular/angular/discussions
Actionshttps://github.com/angular/angular/actions
Projectshttps://github.com/angular/angular/projects
Security and quality40 (40)https://github.com/angular/angular/security
Insightshttps://github.com/angular/angular/insights
https://github.com/angular/angular
New issuehttps://github.com/login?return_to=https://github.com/angular/angular/issues/54881
New issuehttps://github.com/login?return_to=https://github.com/angular/angular/issues/54881
Projected content is not hidden when dynamically creating a component if there is nowhere to project the content yethttps://github.com/angular/angular/issues/54881#top
area: coreIssues related to the framework runtimehttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22area%3A%20core%22
core: content projectionhttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22core%3A%20content%20projection%22
core: dynamic view creationhttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22core%3A%20dynamic%20view%20creation%22
needsTriagehttps://github.com/angular/angular/milestone/83
https://github.com/nolan-white
nolan-whitehttps://github.com/nolan-white
on Mar 15, 2024https://github.com/angular/angular/issues/54881#issue-2188970155
https://private-user-images.githubusercontent.com/111467777/313253853-4d3812df-4a93-4fd8-8f9c-8c3a938157ac.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3OTUyNDA0ODUsIm5iZiI6MTc5NTI0MDE4NSwicGF0aCI6Ii8xMTE0Njc3NzcvMzEzMjUzODUzLTRkMzgxMmRmLTRhOTMtNGZkOC04ZjljLThjM2E5MzgxNTdhYy5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjYxMTIxJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI2MTEyMVQwNTQ5NDVaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1mMzE4NGMzYzk0MTZiODdlMTVhOTNiNDQ4NGQ1N2MxN2VmZWVjZDk1MjliYjAyYjcwM2U5NWUwMmMzZTkzMzc5JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZyZXNwb25zZS1jb250ZW50LXR5cGU9aW1hZ2UlMkZwbmcifQ.cjv7WKriJ40ku8TkwW_ghwxFxp4Jl23uwgHap2JQdyM
https://stackblitz.com/edit/projected-content-not-hidden-dynamic-components?file=src%2Fapp%2Fapp.component.htmlhttps://stackblitz.com/edit/projected-content-not-hidden-dynamic-components?file=src%2Fapp%2Fapp.component.html
https://private-user-images.githubusercontent.com/111467777/313253991-323b9a4c-8225-4285-9a28-6d46052b44b9.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3OTUyNDA0ODUsIm5iZiI6MTc5NTI0MDE4NSwicGF0aCI6Ii8xMTE0Njc3NzcvMzEzMjUzOTkxLTMyM2I5YTRjLTgyMjUtNDI4NS05YTI4LTZkNDYwNTJiNDRiOS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjYxMTIxJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI2MTEyMVQwNTQ5NDVaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT0xYTVmYWU1Yjg5Y2FhOTQwYTM5Mzk5MjIxNzJiN2Q1NjVlM2MzZjE5MzYwNWMyNTBiY2Y1ZDFiM2Y4Mjk2ZGFmJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZyZXNwb25zZS1jb250ZW50LXR5cGU9aW1hZ2UlMkZwbmcifQ.ZLRfGWbGxf8ndM2tO0Fn-RpT6RBUGcdER3SiDrcAWoo
using the suggested alternative to for conditional content projectionhttps://angular.io/guide/content-projection#conditional-content-projection
longstanding workaroundhttps://github.com/angular/components/issues/13784#issuecomment-440137435
cdkDragHandle being ignored when it is placed inside a child componenthttps://github.com/angular/components/issues/13784
https://github.com/alxhub
alxhubhttps://github.com/alxhub
on Mar 16, 2024https://github.com/angular/angular/issues/54881#issuecomment-2000957742
alxhubhttps://github.com/alxhub
area: coreIssues related to the framework runtimehttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22area%3A%20core%22
core: content projectionhttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22core%3A%20content%20projection%22
core: dynamic view creationhttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22core%3A%20dynamic%20view%20creation%22
on Mar 16, 2024https://github.com/angular/angular/issues/54881#event-12138053779
ngbothttps://github.com/apps/ngbot
needsTriagehttps://github.com/angular/angular/milestone/83
on Mar 16, 2024https://github.com/angular/angular/issues/54881#event-12138053849
https://github.com/nolan-white
nolan-whitehttps://github.com/nolan-white
on Mar 18, 2024https://github.com/angular/angular/issues/54881#issuecomment-2004107375
it seems like that is a separate thinghttps://angular.io/api/core/ng-template#context
https://github.com/alxhub
alxhubhttps://github.com/alxhub
on Apr 3, 2024https://github.com/angular/angular/issues/54881#issuecomment-2033342545
https://github.com/nolan-white
nolan-whitehttps://github.com/nolan-white
on Apr 19, 2024https://github.com/angular/angular/issues/54881#issuecomment-2066902189
https://github.com/error-reportingposh
error-reportingposhhttps://github.com/error-reportingposh
on Oct 7, 2025https://github.com/angular/angular/issues/54881#issuecomment-3378697312
https://polish-predominant.github.io/dawson/https://polish-predominant.github.io/dawson/
alxhubhttps://github.com/alxhub
duplicatehttps://github.com/angular/angular/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Aduplicate
Canonical: Content Projection #64504https://github.com/angular/angular/issues/64504
on Oct 18, 2025https://github.com/angular/angular/issues/54881#event-20361459437
https://github.com/apps/angular-automatic-lock-bot
angular-automatic-lock-bothttps://github.com/apps/angular-automatic-lock-bot
on Nov 18, 2025https://github.com/angular/angular/issues/54881#issuecomment-3544418217
automatic conversation locking policyhttps://github.com/angular/angular/blob/f0fbced1c55bc8b8ed9df01cea99df42f3e7eae3/contributing-docs/auto-issue-locking.md
angular-automatic-lock-bothttps://github.com/apps/angular-automatic-lock-bot
on Nov 18, 2025https://github.com/angular/angular/issues/54881#event-21000392303
Sign up for freehttps://github.com/signup?return_to=https://github.com/angular/angular/issues/54881
Sign in to commenthttps://github.com/login?return_to=https://github.com/angular/angular/issues/54881
area: coreIssues related to the framework runtimehttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22area%3A%20core%22
core: content projectionhttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22core%3A%20content%20projection%22
core: dynamic view creationhttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22core%3A%20dynamic%20view%20creation%22
needsTriageNo due datehttps://github.com/angular/angular/milestone/83
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.