Unable to inject ChangeDetectorRef inside host directives
fix(core): unable to inject ChangeDetectorRef inside host directives (#48355)
Unable to inject ChangeDetectorRef inside host directivesfixunable inject changedetectorref inside host directives
Committed by crisbeto
commit message
fix(core): unable to inject ChangeDetectorRef inside host directives (#48355)
When injecting the `ChangeDetectorRef` into a node that matches a component, we create a new ref using the component's LView. This breaks down for host directives, because they run before the component's LView has been created.
These changes resolve the issue by creating the LView before creating the node injector for the directives.
Fixes #48249.
PR Close #48355Editor assessment
Exemplary fix commit. The subject states the observable failure ('unable to inject ChangeDetectorRef inside host directives') in symptom terms, which is appropriate for fixes, with the `core` scope and a PR reference. The body then does everything right: a blank line, the root cause (the ref is built from the component's LView, which does not yet exist for host directives), the fix strategy (create the LView before the node injector), and a clean 'Fixes #48249.' reference tying it to the reported issue. Changelog generation, bisecting, and future refactors all benefit. Hard to improve.