Title: Dynamic component detectChanges trigger ngDoCheck but not refresh view · Issue #39524 · angular/angular · GitHub
Open Graph Title: Dynamic component detectChanges trigger ngDoCheck but not refresh view · Issue #39524 · angular/angular
X Title: Dynamic component detectChanges trigger ngDoCheck but not refresh view · Issue #39524 · angular/angular
Description: This is a related issue of #36667. Reproduce live demo is here. https://stackblitz.com/edit/angular-vz1dca?file=src/app/app.module.ts https://stackblitz.com/edit/angular-7h6eer?file=src/app/app.module.ts code is this. import { Co...
Open Graph Description: This is a related issue of #36667. Reproduce live demo is here. https://stackblitz.com/edit/angular-vz1dca?file=src/app/app.module.ts https://stackblitz.com/edit/angular-7h6eer?file=src/app%2...
X Description: This is a related issue of #36667. Reproduce live demo is here. https://stackblitz.com/edit/angular-vz1dca?file=src/app/app.module.ts https://stackblitz.com/edit/angular-7h6eer?file=src/app%2...
Opengraph URL: https://github.com/angular/angular/issues/39524
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Dynamic component detectChanges trigger ngDoCheck but not refresh view","articleBody":"This is a related issue of #36667. \r\nReproduce live demo is here.\r\nhttps://stackblitz.com/edit/angular-vz1dca?file=src%2Fapp%2Fapp.module.ts\r\nhttps://stackblitz.com/edit/angular-7h6eer?file=src%2Fapp%2Fapp.module.ts\r\n\r\ncode is this.\r\n\r\n```\r\nimport {\r\n Component,\r\n NgModule,\r\n ViewContainerRef,\r\n ComponentFactoryResolver,\r\n Injector,\r\n ChangeDetectionStrategy,\r\n DoCheck\r\n} from \"@angular/core\";\r\nimport { BrowserModule } from \"@angular/platform-browser\";\r\n\r\nimport { timer } from \"rxjs\";\r\n\r\n@Component({\r\n selector: \"dynamic\",\r\n template: `\r\n {{ name }}\r\n `,\r\n changeDetection: ChangeDetectionStrategy.OnPush\r\n})\r\nexport class Dynamic implements DoCheck {\r\n name = \"initial name\";\r\n\r\n ngDoCheck() {\r\n console.log(\"docheck dynamic\");\r\n }\r\n}\r\n\r\n@Component({\r\n selector: \"my-app\",\r\n template: `\r\n \u003cb>Expected\u003c/b>: \"initial name\" changes to \"changed name\" after 2s\u003cbr />\r\n \u003cb>Actual\u003c/b>:\u003cbr />\r\n `,\r\n changeDetection: ChangeDetectionStrategy.OnPush\r\n})\r\nexport class AppComponent {\r\n constructor(\r\n private _vcRef: ViewContainerRef,\r\n private _cfr: ComponentFactoryResolver,\r\n private _injector: Injector\r\n ) {}\r\n\r\n ngOnInit() {\r\n const cmptRef = this._cfr\r\n .resolveComponentFactory(Dynamic)\r\n .create(this._injector);\r\n this._vcRef.insert(cmptRef.hostView);\r\n\r\n setTimeout(() => {\r\n cmptRef.instance.name = \"changed name\";\r\n console.log(\"changing name\");\r\n cmptRef.changeDetectorRef.detectChanges();\r\n }, 2000);\r\n }\r\n}\r\n\r\n@NgModule({\r\n imports: [BrowserModule],\r\n declarations: [AppComponent, Dynamic],\r\n entryComponents: [Dynamic],\r\n bootstrap: [AppComponent]\r\n})\r\nexport class AppModule {}\r\n\r\n```\r\n\r\nThe reason is for `dynamic component`, there is a host view as a placeholder, the `hooks` are registered on the host view not the component view, when calling `componentRef.changeDetectorRef.detectChanges()`, it will run change detection from root host view, and trigger the `doCheck hook`, but when it really want to refresh child component, since it is a onPush component and not marked dirty, it will not be refreshed. \r\n\r\nI will try to resolve this issue in #39463 too.","author":{"url":"https://github.com/JiaLiPassion","@type":"Person","name":"JiaLiPassion"},"datePublished":"2020-10-31T23:38:48Z","url":"https://github.com/angular/angular/issues/39524"}
| 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:b9696659-1c30-aac3-4897-76455e50cebf |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D22A:785A9:A7CD1B:D60AD1:6B00F419 |
| html-safe-nonce | 93680fe0e360500a66e4680e932922c7c348b9b1de97d318c559f9c74c3de225 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMjJBOjc4NUE5OkE3Q0QxQjpENjBBRDE6NkIwMEY0MTkiLCJ2aXNpdG9yX2lkIjoiODU3ODk1MDMxNjk5MjA3MTkzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 15f3cff513ff3dd17ade89404b604965ab1b03f679353ebb44c7e0289031e946 |
| hovercard-subject-tag | issue:733828302 |
| 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/39524/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f31862661604e017afa4f279819d1a6cf769e614e510b80529e1c7ff31094dc4/angular/angular/issues/39524 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f31862661604e017afa4f279819d1a6cf769e614e510b80529e1c7ff31094dc4/angular/angular/issues/39524 |
| og:image:alt | This is a related issue of #36667. Reproduce live demo is here. https://stackblitz.com/edit/angular-vz1dca?file=src/app/app.module.ts https://stackblitz.com/edit/angular-7h6eer?file=src/app%2... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | JiaLiPassion |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4ef498cbabcbe3c50befc7a5b743e7072ee770b4daf0e15e54801180d1fa91fc |
| 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 | 9983dd5da06943f833c971dd5b6bc988e2858be5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width