René's URL Explorer Experiment


Title: viewContainerRef.renderComponent should support hook on hostElement like createComponent function · Issue #51491 · angular/angular · GitHub

Open Graph Title: viewContainerRef.renderComponent should support hook on hostElement like createComponent function · Issue #51491 · angular/angular

X Title: viewContainerRef.renderComponent should support hook on hostElement like createComponent function · Issue #51491 · angular/angular

Description: Which @angular/* package(s) are relevant/related to the feature request? core Description hi @AndrewKushnir, look like ngx-dynamic-hooks work correctly and it using latest version of Angular core I just update. I tried to get rid of flic...

Open Graph Description: Which @angular/* package(s) are relevant/related to the feature request? core Description hi @AndrewKushnir, look like ngx-dynamic-hooks work correctly and it using latest version of Angular core I...

X Description: Which @angular/* package(s) are relevant/related to the feature request? core Description hi @AndrewKushnir, look like ngx-dynamic-hooks work correctly and it using latest version of Angular core I...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"viewContainerRef.renderComponent should support hook on hostElement like createComponent function","articleBody":"### Which @angular/* package(s) are relevant/related to the feature request?\r\n\r\ncore\r\n\r\n### Description\r\n\r\nhi @AndrewKushnir, look like ngx-dynamic-hooks work correctly and it using latest version of Angular core I just update. I tried to get rid of flick and still experience that issue.  I guess since they using renderer2 to render html direct instead of component render,so it cause this problem. So I decide do my own. look at the test file detail give me a lot of clue. But it not cover the case that component selector mix with normal html. \r\n\r\nhttps://github.com/AndrewKushnir/angular/commit/f9d02a7ced21a4569e667f85b05216a2ffe9e169#diff-af4c8e2af18bf92515f7cb47ed0e7a8be798116a9ca5c1e15f2ba4c3aa7b79b6\r\n\r\nWhich is the real world use case. For example I have a html code send from server:\r\n\r\n```\r\ncontent = `\r\n\u003ch1> hello world 1\u003c/h1>  \r\n  \u003cdynamic1> \u003c/dynamic1> \r\n  \u003cdynamic2> \u003c/dynamic2>  \r\n  \u003ch1> hello world 2\u003c/h1>\r\n  `;\r\n  \r\n```\r\n## CONTEXT\r\n- I have a dictionary file to know tag-selector pair with which component.\r\n- I'm using RenderComponent below to render it and it work but it only able to render 1 component. and append it to the last of component as default. \r\n- I want to use selector as the hook and render component to that position but I'm confuse about this place. Now I have two option\r\n\r\n## TWO OPTION\r\n+ using angular _**createComponent() function from angular/core**_ to hook and create, then attachView as tutorial. It look like very useful and promising with hostElement to use as hook. But it just not working...  https://angular.io/api/core/createComponent\r\n\r\n\r\n\r\n+ use _**vcr.createComponent**_ which is work geat. But it only append to last entry. See the index option parameter (index: the index at which to insert the new component's host view into this container. If not specified, appends the new view as the last entry). But this index is angular render level index instead of string position index. What should I do? How can I use that index? Or maybe we can have other solution, since there is no DOM on server to hook on. Maybe I can use renderer3 or something? \r\n\r\n+ since the htmlContent come from server, I can do some regex to mark on selector target like `\u003cdynamic  #youShouldHookHere>\u003c/dynamic1>` or `\u003cng-content> \u003cdynamic1> \u003c/dynamic1> \u003cng-content>`\r\n\r\n```\r\n@Component({\r\n  standalone: true,\r\n  selector: 'dynamic1',\r\n  template: `\r\n  \u003cng-content />\r\n`,\r\n})\r\nclass Dynamic1Component {\r\n}\r\n\r\n@Component({\r\n  standalone: true,\r\n  selector: 'dynamic2',\r\n  template: `\r\n  \u003cng-content />\r\n`,\r\n})\r\nclass Dynamic2Component {\r\n}\r\n\r\n@Component({\r\n  standalone: true,\r\n  selector: 'app',\r\n  template: `\u003cdiv [innerHTML]=\"content\">\u003c/div>`,\r\n})\r\nclass RenderComponent {\r\n  content = `\u003ch1> hello world 1\u003c/h1>  \r\n  \u003cdynamic1> \u003c/dynamic1> \r\n  \u003cdynamic2> \u003c/dynamic2>  \r\n  \u003ch1> hello world 2\u003c/h1>\r\n  `;\r\n  vcr!: ViewContainerRef;\r\n  envInjector = inject(EnvironmentInjector);\r\n\r\n  ngAfterViewInit() {\r\n    // solution 1: this one work but only auto append at last\r\n     const compRef = this.vcr.createComponent(Dynamic1Component);\r\n     compRef.changeDetectorRef.detectChanges();\r\n     \r\n    // QUESTION: but how to render on dynamic1 hook? It will be perfect if we can give some instruction to hook on that to render....\r\n    \r\n    // solution 2: use application ref or use environmentInjector not work at all.\r\n    const compRef = createComponent(Dynamic1Component, {\r\n      // environmentInjector: this.envInjector, // not work\r\n        environmentInjector: this.applicationRef.injector,\r\n    });\r\n  }\r\n}\r\n```\r\n\r\n\r\n### Proposed solution\r\n\r\nIf this one work, it can open a new world for SSR and hydration. Look at the insertImpl function I can see that index is the list of render command. Maybe we can add some renderId to mark on it?\r\n\r\n\r\n![image](https://github.com/angular/angular/assets/16970990/d9a22bb2-21ff-4e24-9bf5-27d6fab031f3)\r\n```\r\n@Component({\r\n  standalone: true,\r\n  selector: 'app',\r\n  template: `\u003cmain>Hi! This is the main content.\u003cdynamic>\u003c/dynamic> \u003c/main>`,\r\n})\r\nclass AppComponent {\r\n  vcr = inject(ViewContainerRef);\r\n\r\n  ngAfterViewInit() {\r\n    const compRef = this.vcr.createComponent(DynamicComponent, { \r\n    hostElement: // propose 1: this one will look like createComponent function,use DOCUMENT in angular/common support by domnio on server \r\n    selector: 'dynamic', //  propose 2:  this solution, so domino will search for hostElement use querySelectorAll\r\n    stringReplace: '\u003cdynamic>\u003c/dynamic>' // propose 3:  let developer parse job, angular just do string replace\r\n     } );\r\n    compRef.changeDetectorRef.detectChanges();\r\n  }\r\n}\r\n  ```\r\n\r\n### Alternatives considered\r\n\r\nThank for your support, I will close this issue once I found the necessary suggestion. \r\n\r\nI'm thinking of recursion component. It will try to render it self. For example:\r\n```\r\n  content = `\u003ch1> hello world 1\u003c/h1>  \r\n  \u003cdynamic1> \u003c/dynamic1> \r\n  \u003cdynamic2> \u003c/dynamic2>  \r\n  \u003ch1> hello world 2\u003c/h1>\r\n  `;\r\n```\r\n\r\nwill be convert to:\r\n\r\n```\r\n  content = `\u003ch1> hello world 1\u003c/h1>  \r\n  \u003crecursion-component [content]=\"'\u003cdynamic1> \u003c\\/dynamic1>'\"> \u003c/recursion-component> \r\n  \u003crecursion-component [content]=\"'\u003cdynamic1> \u003c\\/dynamic1>'\"> \u003c/recursion-component> \r\n  \u003ch1> hello world 2\u003c/h1>\r\n  `;\r\n  ```\r\n  \r\n  So in theory, we only render one and only component `recursion-component` it will detect if it this component is only single component selector content or mix html content and decide to render or continue the recursion loop. \r\n  \r\n  \r\n  ","author":{"url":"https://github.com/hiepxanh","@type":"Person","name":"hiepxanh"},"datePublished":"2023-08-24T08:41:25Z","url":"https://github.com/angular/angular/issues/51491"}

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:31720b40-f801-db9f-1e00-d751508946cc
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id95E2:291B58:B49DD0:E402FB:6B013131
html-safe-nonce8e42cae4f0f35f40e54bc282ac92cc933d19c3f49219932b981e154c8eb61f99
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NUUyOjI5MUI1ODpCNDlERDA6RTQwMkZCOjZCMDEzMTMxIiwidmlzaXRvcl9pZCI6Ijg3NDA4MTU5MDU4NDU0ODk5NjkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac8116226757688e992ec4c9fda653f60c19b8ded431d7ecbd90b051d2c410df72
hovercard-subject-tagissue:1864687050
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/51491/issue_layout
twitter:imagehttps://opengraph.githubassets.com/67102e583dc162240af8645f1e5e6f1dddcbc0618fd5066b34bd43ab4f635baf/angular/angular/issues/51491
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/67102e583dc162240af8645f1e5e6f1dddcbc0618fd5066b34bd43ab4f635baf/angular/angular/issues/51491
og:image:altWhich @angular/* package(s) are relevant/related to the feature request? core Description hi @AndrewKushnir, look like ngx-dynamic-hooks work correctly and it using latest version of Angular core I...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamehiepxanh
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/51491#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fangular%2Fangular%2Fissues%2F51491
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%2F51491
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/51491
Reloadhttps://github.com/angular/angular/issues/51491
Reloadhttps://github.com/angular/angular/issues/51491
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/51491
New issuehttps://github.com/login?return_to=https://github.com/angular/angular/issues/51491
viewContainerRef.renderComponent should support hook on hostElement like createComponent functionhttps://github.com/angular/angular/issues/51491#top
area: coreIssues related to the framework runtimehttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22area%3A%20core%22
needsTriagehttps://github.com/angular/angular/milestone/83
https://github.com/hiepxanh
hiepxanhhttps://github.com/hiepxanh
on Aug 24, 2023https://github.com/angular/angular/issues/51491#issue-1864687050
@AndrewKushnirhttps://github.com/AndrewKushnir
AndrewKushnir@f9d02a7#diff-af4c8e2af18bf92515f7cb47ed0e7a8be798116a9ca5c1e15f2ba4c3aa7b79b6https://github.com/AndrewKushnir/angular/commit/f9d02a7ced21a4569e667f85b05216a2ffe9e169#diff-af4c8e2af18bf92515f7cb47ed0e7a8be798116a9ca5c1e15f2ba4c3aa7b79b6
https://angular.io/api/core/createComponenthttps://angular.io/api/core/createComponent
https://private-user-images.githubusercontent.com/16970990/262915275-d9a22bb2-21ff-4e24-9bf5-27d6fab031f3.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3OTUyNDA1NDIsIm5iZiI6MTc5NTI0MDI0MiwicGF0aCI6Ii8xNjk3MDk5MC8yNjI5MTUyNzUtZDlhMjJiYjItMjFmZi00ZTI0LTliZjUtMjdkNmZhYjAzMWYzLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjExMjElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYxMTIxVDA1NTA0MlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWI3YzdjZTA5Y2VlYTY3ZmQzY2Q0MjJjZTQ1YTVkOWFmMmE4YTBiOWRlYjI5ZWVhYTAxMTE0MGM5NjhiNDljZTQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JnJlc3BvbnNlLWNvbnRlbnQtdHlwZT1pbWFnZSUyRnBuZyJ9.JCxQ2cEZ8O_7Rwv4iJCFnzysL1iK5p50lOmo0xLdFfw
https://github.com/hiepxanh
hiepxanhhttps://github.com/hiepxanh
on Aug 24, 2023https://github.com/angular/angular/issues/51491#issuecomment-1691275632
https://private-user-images.githubusercontent.com/16970990/262917614-a74cefcb-ce30-4114-9777-5565f3386134.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3OTUyNDA1NDIsIm5iZiI6MTc5NTI0MDI0MiwicGF0aCI6Ii8xNjk3MDk5MC8yNjI5MTc2MTQtYTc0Y2VmY2ItY2UzMC00MTE0LTk3NzctNTU2NWYzMzg2MTM0LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjExMjElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYxMTIxVDA1NTA0MlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWY1ZWYwNjhkZmJiYmI5YTFjMGU1NWQ4MTE4M2Y0NWQxZTY4ZjNiOTExZDNiNWNkZWM3ZTJjNDc5MDU1NTFjYzQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JnJlc3BvbnNlLWNvbnRlbnQtdHlwZT1pbWFnZSUyRnBuZyJ9.8_A3fAGiXxLtNW4LyByZB5raSto75r_q-q7Qo3dN6Zc
https://codesandbox.io/p/sandbox/relaxed-feather-27fv8y?file=/src/app/app.component.ts:2,3https://codesandbox.io/p/sandbox/relaxed-feather-27fv8y?file=/src/app/app.component.ts:2,3
#51492https://github.com/angular/angular/issues/51492
hiepxanhhttps://github.com/hiepxanh
on Aug 24, 2023https://github.com/angular/angular/issues/51491#event-10179331127
hiepxanhhttps://github.com/hiepxanh
on Aug 24, 2023https://github.com/angular/angular/issues/51491#event-10179336075
https://github.com/hiepxanh
hiepxanhhttps://github.com/hiepxanh
on Aug 24, 2023https://github.com/angular/angular/issues/51491#issuecomment-1691433750
jessicajaniukhttps://github.com/jessicajaniuk
area: coreIssues related to the framework runtimehttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22area%3A%20core%22
on Aug 24, 2023https://github.com/angular/angular/issues/51491#event-10183504964
ngbothttps://github.com/apps/ngbot
needsTriagehttps://github.com/angular/angular/milestone/83
on Aug 24, 2023https://github.com/angular/angular/issues/51491#event-10183505244
https://github.com/AndrewKushnir
AndrewKushnirhttps://github.com/AndrewKushnir
on Aug 26, 2023https://github.com/angular/angular/issues/51491#issuecomment-1694127351
@hiepxanhhttps://github.com/hiepxanh
https://github.com/hiepxanh
hiepxanhhttps://github.com/hiepxanh
on Aug 27, 2023https://github.com/angular/angular/issues/51491#issuecomment-1694546247
hiepxanhhttps://github.com/hiepxanh
completedhttps://github.com/angular/angular/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Aug 27, 2023https://github.com/angular/angular/issues/51491#event-10200987502
https://github.com/apps/angular-automatic-lock-bot
angular-automatic-lock-bothttps://github.com/apps/angular-automatic-lock-bot
on Sep 27, 2023https://github.com/angular/angular/issues/51491#issuecomment-1736464811
automatic conversation locking policyhttps://github.com/angular/angular/blob/8f24bc9443b3872fe095d9f7f77b308a361a13b4/docs/GITHUB_PROCESS.md#conversation-locking
angular-automatic-lock-bothttps://github.com/apps/angular-automatic-lock-bot
on Sep 27, 2023https://github.com/angular/angular/issues/51491#event-10481068181
Sign up for freehttps://github.com/signup?return_to=https://github.com/angular/angular/issues/51491
Sign in to commenthttps://github.com/login?return_to=https://github.com/angular/angular/issues/51491
area: coreIssues related to the framework runtimehttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22area%3A%20core%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.