Title: NgComponentOutlet projected content control flow issue · Issue #62882 · angular/angular · GitHub
Open Graph Title: NgComponentOutlet projected content control flow issue · Issue #62882 · angular/angular
X Title: NgComponentOutlet projected content control flow issue · Issue #62882 · angular/angular
Description: Which @angular/* package(s) are the source of the bug? common Is this a regression? No Description I am trying to emulate the complex example at the very bottom of the NgComponentOutlet docs. I have found that when I use ViewContainerRef...
Open Graph Description: Which @angular/* package(s) are the source of the bug? common Is this a regression? No Description I am trying to emulate the complex example at the very bottom of the NgComponentOutlet docs. I hav...
X Description: Which @angular/* package(s) are the source of the bug? common Is this a regression? No Description I am trying to emulate the complex example at the very bottom of the NgComponentOutlet docs. I hav...
Opengraph URL: https://github.com/angular/angular/issues/62882
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"NgComponentOutlet projected content control flow issue","articleBody":"### Which @angular/* package(s) are the source of the bug?\n\ncommon\n\n### Is this a regression?\n\nNo\n\n### Description\n\nI am trying to emulate the complex example at the very bottom of the [NgComponentOutlet](https://angular.dev/api/common/NgComponentOutlet) docs. I have found that when I use `ViewContainerRef.createEmbeddedView` to create content using an ng-template that contains control flow, the content IS projected to the screen but NOT in the correct place.\n\n**Simple component that projects content into a gray box**\n```typescript\n@Component({\n selector: 'app-container',\n styles: `:host {display: block; padding: 10px; border: 2px solid lightgray;}`,\n template: `\n \u003cng-content>\u003c/ng-content> \n `,\n})\nexport class ContainerComponent {}\n```\n\n**Main component that uses component outlet**\n```typescript\n@Component({\n selector: 'app-root',\n imports: [NgComponentOutlet],\n template: `\n \u003cng-template #contents>\n \u003c!-- Removing the control flow makes it work -->\n @if(true) {\n Projected from an ng-template (should be inside the box)\n }\n \u003c/ng-template>\n \u003ch1>NgComponentOutlet Control Flow Issue\u003c/h1>\n \u003cng-container *ngComponentOutlet=\"container; content: content\" />\n `,\n})\nexport class App {\n vcr = inject(ViewContainerRef);\n contentTemplate = viewChild.required\u003cTemplateRef\u003cunknown>>('contents');\n container = ContainerComponent;\n content!: Node[][];\n\n constructor() {\n effect(() => {\n this.content = [\n this.vcr.createEmbeddedView(this.contentTemplate()).rootNodes,\n ];\n });\n }\n}\n```\n\n\n\n### Please provide a link to a minimal reproduction of the bug\n\nhttps://stackblitz.com/edit/view-container-ref-create-component-bug?file=src%2Fmain.ts,src%2Fcontainer.ts\n\n### Please provide the exception or error you saw\n\nThe content is not projected into the correct place... it is projected outside of the parent component.\n\n\u003cimg width=\"596\" height=\"143\" alt=\"Image\" src=\"https://github.com/user-attachments/assets/9d22f1c6-33a0-4076-83a8-55408aa86c23\" />\n\n\u003cimg width=\"612\" height=\"141\" alt=\"Image\" src=\"https://github.com/user-attachments/assets/467b5da5-5eaa-4eae-8d7b-937b0afe1501\" />\n\nIf I remove the control flow from the `ng-template`, it works as expected.\n\n\u003cimg width=\"597\" height=\"144\" alt=\"Image\" src=\"https://github.com/user-attachments/assets/0f0b0adf-cafb-4936-996e-f155a1c0be47\" />\n\n\u003cimg width=\"615\" height=\"278\" alt=\"Image\" src=\"https://github.com/user-attachments/assets/9c4eb820-10d4-4d14-bdbd-8cae709c923e\" />\n\n### Please provide the environment you discovered this bug in (run `ng version`)\n\n```true\nAngular CLI: 20.1.3\nNode: 20.19.1\nPackage Manager: npm 10.8.2\nOS: linux x64\n\nAngular: 20.1.3\n... animations, build, cli, common, compiler, compiler-cli, core\n... forms, platform-browser, router\n\nPackage Version\n------------------------------------------------------\n@angular-devkit/architect 0.2001.3\n@angular-devkit/core 20.1.3\n@angular-devkit/schematics 20.1.3\n@schematics/angular 20.1.3\nrxjs 7.8.2\ntypescript 5.8.2\nzone.js 0.15.0\n```\n\n### Anything else?\n\nI feel like this could possibly be related to https://github.com/angular/angular/issues/54881.\n\nThe actual project I'm working on is where I'm emulating `NgComponentOutlet` by using `ViewContainerRef.createComponent` directly, and when I use `TemplateRef.createEmbeddedView` (instead of calling it on the view ref), and then attach it to the application ref, it seems to work.\n\nThis still seems like a bug to me though, or else I believe the documentation needs to be updated.","author":{"url":"https://github.com/jdgarvey","@type":"Person","name":"jdgarvey"},"datePublished":"2025-07-29T18:39:16Z","url":"https://github.com/angular/angular/issues/62882"}
| 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:659c2cce-29be-817b-f18b-32b5197f7d04 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 84B0:37820D:17A3B51:1F5808F:6B013095 |
| html-safe-nonce | f42a672fcd4eeae6512ff65a0387c7c9cfbbc74784606c8f98db1448b8b77eca |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NEIwOjM3ODIwRDoxN0EzQjUxOjFGNTgwOEY6NkIwMTMwOTUiLCJ2aXNpdG9yX2lkIjoiNDYyMTg4MjQ2MTU2MTg5MzAxMyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | e380bf7a0abd358f87f8335fed93f14b1c2427a5dd6c0ffb20d598234b8219bc |
| hovercard-subject-tag | issue:3274608738 |
| 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/62882/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f04f9586cb1ebf8e61fd1a83c55d507dfcf53208809b5fee166388dfb1c005b6/angular/angular/issues/62882 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f04f9586cb1ebf8e61fd1a83c55d507dfcf53208809b5fee166388dfb1c005b6/angular/angular/issues/62882 |
| og:image:alt | Which @angular/* package(s) are the source of the bug? common Is this a regression? No Description I am trying to emulate the complex example at the very bottom of the NgComponentOutlet docs. I hav... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jdgarvey |
| 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