ComponentRef Change detector doesn't trigger detecting for view
See original GitHub issueš bug report
Affected Package
The issue is caused by package @angular/coreIs this a regression?
Cannot sayDescription
Component created by #ComponentFactoryResolver.
ComponentFactoryResolver#createComponent returns ComponentRef that does have changeDetectorRef.
After any changes to componentās input by code (not by template) and invocation of such ComponentRef#changeDetectorRef.detectChanges componentās view wonāt be updated.
example from repro: dynamic-wrapper.component.ts#createComponent.
componentRef.changeDetectorRef.detectChanges()
This is root issue.
To testing purposes ChangeDetectorRef was be added to componentās constructor and invoked by consumer of this ComponentFactoryResolver. CDR from componentās injector works as expected
example from repro: dynamic-wrapper.component.ts#createComponent
componentRef.instance.cdr.detectChanges()
š¬ Minimal Reproduction
GitHub repro repository: https://github.com/RolginRoman/ng-dynamic-components-cdr-repro
š„ Exception or Error
No exception
š Your Environment
Angular Version:
Angular version 9.1.0
Anything else relevant?
Seems like browser, OS version or anything else doesnāt matter
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:12 (4 by maintainers)
Workarroud Is to use componentās injector to get Real ChangeDetectorRef.
ComponentRef.injector.get(ChangeDetectorRef)
This was just fixed via #46641 - the ComponentRef has a new method -
setInput
that correctly sets an input and makes sure that change detection is properly invoked. More details in #46641