Skip to content

Directive can't inject host's ChangeDetectorRef #12816

Closed

Description

@stringham

I'm submitting a ... (check one with "x")

[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

If a directive injects a ChangeDetectorRef it receives the parent element's instance rather than the one on the host element.

I'm not sure if this is intentional, but it seems like there should be a way for the directive to use the host element's ChangeDetectorRef.

Expected behavior

A directive should be able to inject the host element's ChangeDetectorRef

Minimal reproduction of the problem with instructions

I created a directive called RenderOnce that detaches the change detector in ngAfterViewInit.

http://plnkr.co/edit/HKF7etipvdVdl65RaWLG?p=preview

I have two elements that increment a number on an interval, one of them I add the directive, the other one I don't. But the directive detaches the parent component's change detector so they both only render once.

Activity

  1. added
    area: coreIssues related to the framework runtime
    on Nov 11, 2016
  2. dfala commented on Nov 23, 2016

    @dfala

    Any updates on fixing this bug? This is a UGE issue for me.

  3. hccampos commented on Mar 7, 2017

    @hccampos

    @dfala seems like this is fixed in rc.2

  4. DzmitryShylovich commented on Mar 7, 2017

    @DzmitryShylovich
    Contributor
  5. hccampos commented on Mar 7, 2017

    @hccampos

    @DzmitryShylovich that is right, never mind. Here the use case was a directive to integrate with MobX (https://github.com/mobxjs/mobx-angular) and in that case it is actually acceptable to get the parent's change detector, hence why I thought it had been fixed.

  6. tbosch commented on Apr 11, 2017

    @tbosch
    Contributor

    This also happens when using Injector.get(ChangeDetectorRef), see #14656

  7. self-assigned this
    on Apr 27, 2017
  8. added a commit that references this issue on May 4, 2017
    f66e59e
  9. added a commit that references this issue on Aug 11, 2017
    1ce567e
  10. added a commit that references this issue on Aug 28, 2017
    b027ccc
  11. angular-automatic-lock-bot commented on Sep 11, 2019

    @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.

  12. locked and limited conversation to collaborators on Sep 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions