Title: Add the ability to set projectableNodes after createComponent · Issue #51421 · angular/angular · GitHub
Open Graph Title: Add the ability to set projectableNodes after createComponent · Issue #51421 · angular/angular
X Title: Add the ability to set projectableNodes after createComponent · Issue #51421 · angular/angular
Description: Which @angular/* package(s) are relevant/related to the feature request? @angular/core Description Currently the only way to add projectable nodes is to set them in one of the createComponent variants (ViewContainerRef.createComponent, c...
Open Graph Description: Which @angular/* package(s) are relevant/related to the feature request? @angular/core Description Currently the only way to add projectable nodes is to set them in one of the createComponent varia...
X Description: Which @angular/* package(s) are relevant/related to the feature request? @angular/core Description Currently the only way to add projectable nodes is to set them in one of the createComponent varia...
Opengraph URL: https://github.com/angular/angular/issues/51421
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Add the ability to set projectableNodes after createComponent","articleBody":"### Which @angular/* package(s) are relevant/related to the feature request?\r\n\r\n@angular/core\r\n\r\n### Description\r\n\r\nCurrently the only way to add projectable nodes is to set them in one of the createComponent variants (ViewContainerRef.createComponent, createComponent ... ).\r\n\r\nThe Problem with this approach is that it is not possible to get the injection hierarchy right when multiple nested components are created dynamically ( Example: https://stackblitz.com/edit/angular-xh1j19?file=src%2Fmain.ts) \r\n\r\nSo reproducing the following scenario dynamically is not possible\r\n```\r\n\u003ccmp1>\r\n \u003ccmp2/>\r\n\u003c/cmp1>\r\n```\r\nthe best we can do is \r\n```\r\nconst cmp2 = viewContainerRef.createComponent(Cmp2, /* { injector: NEED_INJECTOR_OF_CMP1_HERE } */ );\r\nconst cmp1 = viewContainerRef.createComponent(Cmp1, { projectableNodes: [[cmp2.location.nativeElement]]});\r\n```\r\nbut this is a problem if CMP1 has component providers!\r\n\r\nTo get the same injection hierarchy as with the declarative approach we would need something like\r\n```\r\nconst cmp1 = viewContainerRef.createComponent(Cmp1);\r\nconst cmp2 = viewContainerRef.createComponent(Cmp2, { injector: cmp1.injector } );\r\ncmp1.setProjectableNodes([[cmp2.location.nativeElement]]);\r\n```\r\nso something like **ComponentRef.setProjectableNodes** is missing\r\n\r\n### Proposed solution\r\n\r\nadd a method `setProjectableNodes` to `ComponentRef`;\r\n\r\nThis allows to create the components in the same order as it would be done in template, and therefore it would be possible to get the injection hierarchy right\r\n\r\n\r\n### Alternatives considered\r\n\r\n---","author":{"url":"https://github.com/demike","@type":"Person","name":"demike"},"datePublished":"2023-08-18T10:09:36Z","url":"https://github.com/angular/angular/issues/51421"}
| 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:df91e245-9771-8dd0-f34d-f207427ae374 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 990C:317608:16DF22D:1CFEFFC:6B013538 |
| html-safe-nonce | 0af7ec1b88dfdc7577a24dcc9bb35df9b021ecf5663c9ddb45625c2deb403916 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5OTBDOjMxNzYwODoxNkRGMjJEOjFDRkVGRkM6NkIwMTM1MzgiLCJ2aXNpdG9yX2lkIjoiMTg1MzQxOTAyMzQwNTY4Mzc2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | ca82500111bd2d12365cf3faf8028a6131f78c6d7a1e98bde26905db419941cd |
| hovercard-subject-tag | issue:1856453693 |
| 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/51421/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7157f59d312a01b226128a8e3c839c7d7f7dafc8a3e29781d6bf6ad31492c16f/angular/angular/issues/51421 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7157f59d312a01b226128a8e3c839c7d7f7dafc8a3e29781d6bf6ad31492c16f/angular/angular/issues/51421 |
| og:image:alt | Which @angular/* package(s) are relevant/related to the feature request? @angular/core Description Currently the only way to add projectable nodes is to set them in one of the createComponent varia... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | demike |
| 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 | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width