Title: Dynamic standalone component can not resolve FormsModule (probably others from @angular/*) · Issue #48034 · angular/angular · GitHub
Open Graph Title: Dynamic standalone component can not resolve FormsModule (probably others from @angular/*) · Issue #48034 · angular/angular
X Title: Dynamic standalone component can not resolve FormsModule (probably others from @angular/*) · Issue #48034 · angular/angular
Description: Which @angular/* package(s) are the source of the bug? core Is this a regression? No Description I have a standalone component defined like this: import { CommonModule } from '@angular/common'; import { FormsModule } from '@angular/forms...
Open Graph Description: Which @angular/* package(s) are the source of the bug? core Is this a regression? No Description I have a standalone component defined like this: import { CommonModule } from '@angular/common'; imp...
X Description: Which @angular/* package(s) are the source of the bug? core Is this a regression? No Description I have a standalone component defined like this: import { CommonModule } from '@angular/common...
Opengraph URL: https://github.com/angular/angular/issues/48034
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Dynamic standalone component can not resolve FormsModule (probably others from @angular/*)","articleBody":"### Which @angular/* package(s) are the source of the bug?\r\n\r\ncore\r\n\r\n### Is this a regression?\r\n\r\nNo\r\n\r\n### Description\r\n\r\nI have a standalone component defined like this: \r\n```TS\r\nimport { CommonModule } from '@angular/common';\r\nimport { FormsModule } from '@angular/forms';\r\n\r\nexport const componentMetadata : Component = {\r\n\tjit: true,\r\n\tstandalone: true,\r\n\tselector: '\u003cdynamic-component>',\r\n\timports: [\r\n\t\tFormsModule, CommonModule\r\n\t],\r\n};\r\nexport class DynamicComponent {\r\n\t\r\n\tpublic constructor() {}\r\n....\r\n}\r\n```\r\nThen I have component that should create dynamically, as a child, this component, with template that is coming from DB.\r\nSample code:\r\n```TS\r\nimport ....\r\n\r\n@Component({\r\n\tstandalone: true,\r\n\tselector: '\u003ccontainer-component>',\r\n\ttemplate: '\u003cng-container #content>\u003c/ng-container>',\r\n\tproviders: [ {\r\n\t\tprovide: NG_VALUE_ACCESSOR,\r\n\t\tuseExisting: forwardRef(() => ContainerComponent),\r\n\t\tmulti: true\r\n\t}],\r\n})\r\n\r\nexport class ContainerComponent implements OnInit, OnDestroy, ControlValueAccessor {\r\n.....\r\n @ViewChild('content', { read: ViewContainerRef, static: true })\r\n contentContainer: ViewContainerRef;\r\n.....\r\n private async createContent() {\r\n\tthis.cleanComponentRef();\r\n\tconst component = await this.setupContentComponent(this.content); // we have content when we reach this method\r\n\tthis.componentRef = this.contentContainer.createComponent(component, {\r\n\t\tinjector: this.contentContainer.injector,\r\n\t});\r\n }\r\n\r\n private async setupContentComponent(content: string = '') {\r\n\tconst defs = await import('./dynamic.component');\r\n\tconst currentMeta = { ...defs.componentMetadata };\r\n\tcurrentMeta.template = content;\r\n\r\n\treturn Component(currentMeta)(defs.DynamicComponent);\r\n }\r\n\r\n private cleanComponentRef() {\r\n\tif (this.componentRef) {\r\n\t this.componentRef.destroy();\r\n\t delete this.componentRef;\r\n }\r\n }\r\n}\r\n```\r\n\r\nThe content is angular template with directives like `ngModel`.\r\nThe problem is that i get a lot of `Can't bind to 'ngModel' since it isn't a known property of....`, but Forms module is imported in the dynamic component and should be compiled properly (IMO)\r\n\r\nDuring investigation I reached a function in core.mjs `function getStandaloneDefFunctions(type, imports) {`\r\nwhen checking for exported directives in this code:\r\n\r\n```TS\r\nif (!!getNgModuleDef(dep)) {\r\n const scope = transitiveScopesFor(dep);\r\n for (const dir of scope.exported.directives) {\r\n```\r\ndep (FormsModule) doesn't have any exported members\r\n\r\nscope {\r\n \"schemas\": null,\r\n \"compilation\": {\r\n \"directives\": {},\r\n \"pipes\": {}\r\n },\r\n \"exported\": {\r\n \"directives\": {},\r\n \"pipes\": {}\r\n }\r\n}\r\n\r\n\r\n### Please provide a link to a minimal reproduction of the bug\r\n\r\n[StackBlitz](https://stackblitz.com/edit/angular-ivy-ayuth7?file=src/app/app.component.html)\r\n\r\n### Please provide the exception or error you saw\r\n\r\n```true\r\nNG0303: Can't bind to 'ngModel' since it isn't a known property of\r\n```\r\n\r\n\r\n### Please provide the environment you discovered this bug in (run `ng version`)\r\n\r\n```true\r\nAngular CLI: 14.2.9\r\nNode: 19.0.1 (Unsupported)\r\nPackage Manager: npm 8.19.2 \r\nOS: linux x64\r\n\r\nAngular: 14.2.10\r\n... animations, common, compiler, compiler-cli, core, forms\r\n... localize, platform-browser, platform-browser-dynamic, router\r\n\r\nPackage Version\r\n---------------------------------------------------------\r\n@angular-devkit/architect 0.1402.9\r\n@angular-devkit/build-angular 14.2.9\r\n@angular-devkit/core 14.2.9\r\n@angular-devkit/schematics 14.2.9\r\n@angular/cdk 14.2.7\r\n@angular/cli 14.2.9\r\n@schematics/angular 14.2.9\r\nrxjs 7.5.7\r\ntypescript 4.7.4\r\n```\r\n\r\n\r\n### Anything else?\r\n\r\nThis is happening when `aot: true` in angular.json\r\nWhen `aot: false`, then all is working but then template translations (all tags in .html files having `i18n` attribute) are not expanded, but all `@localize'text'` messages are. Probably this is for another issue / discussion","author":{"url":"https://github.com/ghost81","@type":"Person","name":"ghost81"},"datePublished":"2022-11-11T17:59:53Z","url":"https://github.com/angular/angular/issues/48034"}
| 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:495807d5-10dc-9d67-7e77-030814411e05 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DE0C:B53AF:1076A29:15EF71D:6B011404 |
| html-safe-nonce | 1f828bc796346a7e570dfded38b65822613b72e4fbf21250563a03a9d46af654 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERTBDOkI1M0FGOjEwNzZBMjk6MTVFRjcxRDo2QjAxMTQwNCIsInZpc2l0b3JfaWQiOiIzNjI1NzYxNDI5NzIzODc4NDA0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 6cfc8f0642a9f789351455b4dc888745ba282e0c1f8eb7cef6f3316315e038b0 |
| hovercard-subject-tag | issue:1445825210 |
| 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/48034/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f3d145c9ca9da60340e7495a25669f0e4d8ad9a50da144ec36191319709e1c85/angular/angular/issues/48034 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f3d145c9ca9da60340e7495a25669f0e4d8ad9a50da144ec36191319709e1c85/angular/angular/issues/48034 |
| og:image:alt | Which @angular/* package(s) are the source of the bug? core Is this a regression? No Description I have a standalone component defined like this: import { CommonModule } from '@angular/common'; imp... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ghost81 |
| hostname | github.com |
| expected-hostname | github.com |
| None | cb7fa109eca7d4156c889f474306b0e91336055e9adf8fd4684b61e49094d124 |
| 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 | 2b59d31a4e44f08b7af67a4b67f8fd0af3befe2a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width