Title: Support for Dynamic Content Projection · Issue #8563 · angular/angular · GitHub
Open Graph Title: Support for Dynamic Content Projection · Issue #8563 · angular/angular
X Title: Support for Dynamic Content Projection · Issue #8563 · angular/angular
Description: Use Case
Open Graph Description: Use Case
X Description: Use Case <ng-content> allows for static (compile time resolution) projection of content. There are cases where the projection needs to be controlled programmatically. A common example is when...
Opengraph URL: https://github.com/angular/angular/issues/8563
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Support for Dynamic Content Projection","articleBody":"# Use Case\n\n`\u003cng-content>` allows for static (compile time resolution) projection of content. There are cases where the projection needs to be controlled programmatically. A common example is when the parent component would like to wrap/decorate the child components during projection.\n# Mental Model\n\nThe mental model would be that `\u003cng-content>` is for fast static projection, but for dynamic projection one would use a query to get a hold of the child components in the form of `ViewRef`s which could then be inserted programmatically at any location in the tree.\n# Possible Solution\n- `ContentViewRef` extends `ViewRef`\n- `@Content(selector)` Provides a way to select direct children content elements using CSS selectors. (This would be after directives such as `ngFor` would unroll the content, and it would be in the correct order.)\n- This would allow selection of elements rather than directives. These `ContentViewRef`s could then be reinserted to any `ViewContainerRef`\n- We would need `ngViewOutlet` (similar to `ngTemplateOutlet`).\n\n``` ts\n@Component({\n template: `\n \u003cdiv *ngFor=\"let view of allViews\">\n \u003ctemplate ngViewOutlet=\"view\">\u003c/template>\n \u003c/div>\n \u003cng-content>\u003c!-- project non selected nodes, such as text nodes -->\u003c/ng-content>\n`\n})\nclass MySelect {\n @Content('*') allViews: ContentViewRef[];\n\n // another example\n @Content('my-option') optionViews: ContentViewRef[];\n}\n```\n\n``` ts\n@Component({\n selector: 'app',\n template: `\n\u003cmy-select>\n Option\n \u003cmy-option>header\u003c/my-option>\n \u003cmy-option *ngFor=\"let item in items\">unrolled items {{item}}\u003c/my-option>\n \u003cmy-option-group>\n \u003cmy-option>\n foo \u003cb>bar\u003c/b>\n \u003cother-directive />\n\u003c/my-option>\n \u003cmy-separator>\u003c/my-separator>\n \u003cmy-option>\u003c/my-option>\n\u003c/my-option-group>\n\u003c/my-select>\n`\n})\nclass App {}\n```\n","author":{"url":"https://github.com/mhevery","@type":"Person","name":"mhevery"},"datePublished":"2016-05-10T04:23:31Z","url":"https://github.com/angular/angular/issues/8563"}
| 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:7c437ef6-b695-1b5a-6a30-77f4b9e78527 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | ED3E:882E2:155FB6A:1C27048:6B0124DA |
| html-safe-nonce | 138fc30ef58622da1f020f4cc800396881107bc0415df425525cbdfaaac45618 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFRDNFOjg4MkUyOjE1NUZCNkE6MUMyNzA0ODo2QjAxMjREQSIsInZpc2l0b3JfaWQiOiIxOTI3MjMxMzMxNjUwMDUzMzM4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | df72ceb5aafbcb2980b496708306483d12b64eec90529eabe9d1fc2ba4724ade |
| hovercard-subject-tag | issue:153921268 |
| 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/8563/issue_layout |
| twitter:image | https://opengraph.githubassets.com/79e174b4875336cdf1f0320b6eeb79fc1c5f68f3f2d46cda03d742dc094fc827/angular/angular/issues/8563 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/79e174b4875336cdf1f0320b6eeb79fc1c5f68f3f2d46cda03d742dc094fc827/angular/angular/issues/8563 |
| og:image:alt | Use Case |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mhevery |
| 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