Skip to content

Component's host directives should be able to inject its ChangeDetectorRef #48249

Closed

Description

@th0r

Which @angular/* package(s) are the source of the bug?

core

Is this a regression?

No

Description

Angular v15 introduced hostDirectives, but currently injecting ChangeDetectorRef in them injects not the host component's cdRef (which would be logical as for me), but some strange cdRef with all the props undefined so calling its detectChanges method throws a TypeError: Cannot read properties of undefined (reading '1') because its _lView array is undefined as well.

To reproduce clone the reproduction repo, run npm i && npm start, open browser and dev tools and see the error in the console.

Please provide a link to a minimal reproduction of the bug

https://github.com/th0r/ng-host-directives-cd-ref

Please provide the exception or error you saw

ERROR TypeError: Cannot read properties of undefined (reading '1')
    at ViewRef$1.detectChanges (core.mjs:13927:38)
    at eval (VM6814 some-host.directive.ts:19:15)
    at timer (zone.js:2321:27)
    at _ZoneDelegate.invokeTask (zone.js:370:171)
    at eval (core.mjs:26142:49)
    at AsyncStackTaggingZoneSpec.onInvokeTask (core.mjs:26142:30)
    at _ZoneDelegate.invokeTask (zone.js:370:54)
    at Object.onInvokeTask (core.mjs:26451:25)
    at _ZoneDelegate.invokeTask (zone.js:370:54)
    at Zone.runTask (zone.js:175:37)

Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 15.0.1
Node: 16.17.1
Package Manager: npm 8.19.2
OS: darwin x64

Angular: 15.0.1
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1500.1
@angular-devkit/build-angular   15.0.1
@angular-devkit/core            15.0.1
@angular-devkit/schematics      15.0.1
@schematics/angular             15.0.1
rxjs                            7.5.7
typescript                      4.8.4

Anything else?

No response

Activity

  1. added
    area: core
    on Nov 28, 2022
  2. added this to the needsTriage milestone on Nov 28, 2022
  3. added
    P3
    on Nov 30, 2022
  4. modified the milestones: needsTriage, Backlog on Nov 30, 2022
  5. self-assigned this
    on Dec 5, 2022
  6. added a commit that references this issue on Dec 7, 2022
    e4dcaa5
  7. angular-automatic-lock-bot commented on Jan 7, 2023

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  8. locked and limited conversation to collaborators on Jan 7, 2023
  9. added a commit that references this issue on Feb 1, 2023
    c4c6f86
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P3area: corebugcore: host directivesstate: has PR

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions