Title: Cannot create component without inserting into DOM without the deprecated `ComponentFactory` · Issue #45263 · angular/angular · GitHub
Open Graph Title: Cannot create component without inserting into DOM without the deprecated `ComponentFactory` · Issue #45263 · angular/angular
X Title: Cannot create component without inserting into DOM without the deprecated `ComponentFactory` · Issue #45263 · angular/angular
Description: Which @angular/* package(s) are the source of the bug? core Is this a regression? No Description Since Angular 13 ComponentFactory.create() is deprecated. It is advertised that we should instead use ViewContainerRef.createComponent(). Ho...
Open Graph Description: Which @angular/* package(s) are the source of the bug? core Is this a regression? No Description Since Angular 13 ComponentFactory.create() is deprecated. It is advertised that we should instead us...
X Description: Which @angular/* package(s) are the source of the bug? core Is this a regression? No Description Since Angular 13 ComponentFactory.create() is deprecated. It is advertised that we should instead us...
Opengraph URL: https://github.com/angular/angular/issues/45263
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Cannot create component without inserting into DOM without the deprecated `ComponentFactory`","articleBody":"### Which @angular/* package(s) are the source of the bug?\n\ncore\n\n### Is this a regression?\n\nNo\n\n### Description\n\nSince Angular 13 `ComponentFactory.create()` is deprecated. It is advertised that we should instead use `ViewContainerRef.createComponent()`. However the behavior between those two methods are different and cannot necessarily replace each other for all use-cases.\r\n\r\nMy use-case is to create a component dynamically, **not** insert it into DOM, call a few custom methods on it, and then destroy the component. But `ViewContainerRef.createComponent()` will always insert the newly created component into DOM, wreaking havoc in my layout.\r\n\r\nBasically I'd like to do something like that:\r\n\r\n```ts\r\nprivate validate(component: Type\u003cDropdownComponent>): boolean {\r\n const injector = Injector.create({providers: this.getMyCustomProvider(), parent: this.getMyParentInjector()});\r\n const factory = this.componentFactoryResolver.resolveComponentFactory\u003cDropdownComponent>(component);\r\n\r\n const dropdownComponentRef = factory.create(injector);\r\n const result = dropdownComponentRef.instance.isValid();\r\n dropdownComponentRef.destroy();\r\n\r\n return result;\r\n}\r\n```\r\n\r\nWas it intentional that a component cannot be instantiated without being inserted into DOM anymore ? Or should it be considered a regression in the feature set of the framework ?\r\n\r\nOr is there an alternative API that would allow me to instantiate and destroy components without ever inserting them into DOM ?\n\n### Please provide a link to a minimal reproduction of the bug\n\n_No response_\n\n### Please provide the exception or error you saw\n\n_No response_\n\n### Please provide the environment you discovered this bug in (run `ng version`)\n\n```true\nAngular CLI: 13.2.5\r\nNode: 14.19.0\r\nPackage Manager: yarn 1.22.17\r\nOS: linux x64\r\n\r\nAngular: 13.2.5\r\n... animations, cdk, cli, common, compiler, compiler-cli, core\r\n... forms, language-service, localize, material\r\n... platform-browser, platform-browser-dynamic, router\r\n\r\nPackage Version\r\n---------------------------------------------------------\r\n@angular-devkit/architect 0.1302.5\r\n@angular-devkit/build-angular 13.2.5\r\n@angular-devkit/core 13.2.5\r\n@angular-devkit/schematics 13.2.5\r\n@angular/flex-layout 13.0.0-beta.38\r\n@schematics/angular 13.2.5\r\nng-packagr 13.2.1\r\nrxjs 7.5.4\r\ntypescript 4.5.5\n```\n\n\n### Anything else?\n\n_No response_","author":{"url":"https://github.com/PowerKiKi","@type":"Person","name":"PowerKiKi"},"datePublished":"2022-03-04T13:57:35Z","url":"https://github.com/angular/angular/issues/45263"}
| 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:6bdb95ce-7152-e278-d923-e527c17aee1b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C4E2:19AA62:C01006:F56FBE:6B00FC60 |
| html-safe-nonce | 35e641869c491c2c75fbf63602ac2b265f4c3dfe8a556993bef60c715d2c4536 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNEUyOjE5QUE2MjpDMDEwMDY6RjU2RkJFOjZCMDBGQzYwIiwidmlzaXRvcl9pZCI6IjUxNjIzMTcyMzMzMjIwNTY2NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 53e3f82b17d46708d0439744f0035f9abd26d7378e7b3a2f9131041f8a0a213f |
| hovercard-subject-tag | issue:1159675863 |
| 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/45263/issue_layout |
| twitter:image | https://opengraph.githubassets.com/03a67b9c4a1e9a753f81545bc4a70b9a7ece3612153390c39faf1fca53818d93/angular/angular/issues/45263 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/03a67b9c4a1e9a753f81545bc4a70b9a7ece3612153390c39faf1fca53818d93/angular/angular/issues/45263 |
| og:image:alt | Which @angular/* package(s) are the source of the bug? core Is this a regression? No Description Since Angular 13 ComponentFactory.create() is deprecated. It is advertised that we should instead us... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | PowerKiKi |
| hostname | github.com |
| expected-hostname | github.com |
| None | e208d86428ec00a57ade75058166297440e8128a01e5287c31a53dc042bbf187 |
| 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 | 7dafd017fb7809a839c443dba08622af38e63c09 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width