Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Directive can't inject host's ChangeDetectorRef #12816

Closed
stringham opened this issue Nov 11, 2016 · 6 comments
Closed

Directive can't inject host's ChangeDetectorRef #12816

stringham opened this issue Nov 11, 2016 · 6 comments
Assignees
Labels
area: core Issues related to the framework runtime freq2: medium type: bug/fix

Comments

@stringham
Copy link

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.

@vicb vicb added the area: core Issues related to the framework runtime label Nov 11, 2016
@dfala
Copy link

dfala commented Nov 23, 2016

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

@hccampos
Copy link

hccampos commented Mar 7, 2017

@dfala seems like this is fixed in rc.2

@DzmitryShylovich
Copy link
Contributor

@hccampos
Copy link

hccampos commented Mar 7, 2017

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

@tbosch
Copy link
Contributor

tbosch commented Apr 11, 2017

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

@tbosch tbosch self-assigned this Apr 27, 2017
tbosch added a commit to tbosch/angular that referenced this issue Apr 27, 2017
…Ref`.

When a directive lives on the same element as a component
(e.g. `<my-comp myDir>`), the directive was not able to get hold
of the `ChangeDetectorRef` of the component on that element. However,
as directives are supposed to decorate components, this is incorrect.

This commit enables this use case.

Closes angular#12816
tbosch added a commit to tbosch/angular that referenced this issue Apr 28, 2017
…Ref`.

When a directive lives on the same element as a component
(e.g. `<my-comp myDir>`), the directive was not able to get hold
of the `ChangeDetectorRef` of the component on that element. However,
as directives are supposed to decorate components, this is incorrect.

This commit enables this use case.

Closes angular#12816
tbosch added a commit to tbosch/angular that referenced this issue Apr 28, 2017
…Ref`.

When a directive lives on the same element as a component
(e.g. `<my-comp myDir>`), the directive was not able to get hold
of the `ChangeDetectorRef` of the component on that element. However,
as directives are supposed to decorate components, this is incorrect.

This commit enables this use case.

Closes angular#12816
@tbosch tbosch moved this from Prio_col0 to Done in Compiler Apr 29, 2017
matsko pushed a commit that referenced this issue May 4, 2017
…Ref`. (#16394)

When a directive lives on the same element as a component
(e.g. `<my-comp myDir>`), the directive was not able to get hold
of the `ChangeDetectorRef` of the component on that element. However,
as directives are supposed to decorate components, this is incorrect.

This commit enables this use case.

Closes #12816
asnowwolf pushed a commit to asnowwolf/angular that referenced this issue Aug 11, 2017
…Ref`. (angular#16394)

When a directive lives on the same element as a component
(e.g. `<my-comp myDir>`), the directive was not able to get hold
of the `ChangeDetectorRef` of the component on that element. However,
as directives are supposed to decorate components, this is incorrect.

This commit enables this use case.

Closes angular#12816
juleskremer pushed a commit to juleskremer/angular that referenced this issue Aug 28, 2017
…Ref`. (angular#16394)

When a directive lives on the same element as a component
(e.g. `<my-comp myDir>`), the directive was not able to get hold
of the `ChangeDetectorRef` of the component on that element. However,
as directives are supposed to decorate components, this is incorrect.

This commit enables this use case.

Closes angular#12816
@tbosch tbosch removed this from Done in Compiler Oct 3, 2017
@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: core Issues related to the framework runtime freq2: medium type: bug/fix
Projects
None yet
Development

No branches or pull requests

7 participants