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

A projected template is subject to a ChangeDetectionRef which is not controlling the template #14321

Closed
HarmenM opened this issue Feb 6, 2017 · 6 comments
Labels

Comments

@HarmenM
Copy link

HarmenM commented Feb 6, 2017

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

[x] bug report
[ ] feature request
[ ] support request

Current behavior
When projecting a template into another component as a ContentChild, the template is subjected to the ChangeDetectorRef of the host component and not of the component in which the template is defined. This results in a situation in which a projected component is not notified of changes.

Expected behavior
A template needs to be independent of the changeDetectionRef in which the template is projected, because there is no direct relation between the two components.

Minimal reproduction of the problem with instructions
A reproduction of the issue can be found here: https://plnkr.co/edit/tU4EPzvtDSoPBlMuwvRH?p=preview

This plunkr reproduces the problem. A template containing a ProjectedComponent is projected into the TestComponent. All of this is defined in the TestApp Component. The ProjectedComponent has an @Input which can be changed by editing the input element. However, due to the OnPush changedetection stategy of the TestComponent, the value is not updated in the ProjectedComponent.

It seems that the projected content is subject to the wrong ChangeDetectionStrategy making it impossible to project rich content into another component without (somehow) exposing the changedetection strategy of the host component.

What is the motivation / use case for changing the behavior?

Please tell us about your environment:
Just a browser (JIT)

  • Angular version: 2.X

  • Browser: all

  • Language: Typescript

@Hikariii
Copy link

Pinging to see if anyone can verify / label this issue

@DzmitryShylovich
Copy link
Contributor

When projecting a template into another component as a ContentChild, the template is subjected to the ChangeDetectorRef of the host component and not of the component in which the template is defined

sounds reasonable to me. @mhevery what do you think?

@tbosch
Copy link
Contributor

tbosch commented Apr 10, 2017

Agree, we should change this.

@tbosch tbosch added this to Prio_col0 in Compiler May 3, 2017
@tbosch
Copy link
Contributor

tbosch commented May 3, 2017

Needed for G3 as well!

@tbosch tbosch self-assigned this May 4, 2017
tbosch added a commit to tbosch/angular that referenced this issue May 5, 2017
… component is dirty checked.

Previously a projected view was only dirty checked when the 
component in which it was inserted was dirty checked.

This fix changes the behavior so that a view is also dirty checked if
the declaring component is dirty checked.

Note: This does not change the order of change detection,
only the fact whether a projected view is dirty checked or not.

Fixes angular#14321
tyler-gh pushed a commit to lucidsoftware/angular that referenced this issue May 5, 2017
… component is dirty checked.

Previously a projected view was only dirty checked when the 
component in which it was inserted was dirty checked.

This fix changes the behavior so that a view is also dirty checked if
the declaring component is dirty checked.

Note: This does not change the order of change detection,
only the fact whether a projected view is dirty checked or not.

Fixes angular#14321
@mhevery mhevery closed this as completed in fcc91d8 May 8, 2017
@tbosch tbosch moved this from Prio_col0 to Done in Compiler May 9, 2017
jasonaden pushed a commit to jasonaden/angular that referenced this issue May 10, 2017
… component is dirty checked. (angular#16592)

Previously a projected view was only dirty checked when the
component in which it was inserted was dirty checked.

This fix changes the behavior so that a view is also dirty checked if
the declaring component is dirty checked.

Note: This does not change the order of change detection,
only the fact whether a projected view is dirty checked or not.

Fixes angular#14321
asnowwolf pushed a commit to asnowwolf/angular that referenced this issue Aug 11, 2017
… component is dirty checked. (angular#16592)

Previously a projected view was only dirty checked when the
component in which it was inserted was dirty checked.

This fix changes the behavior so that a view is also dirty checked if
the declaring component is dirty checked.

Note: This does not change the order of change detection,
only the fact whether a projected view is dirty checked or not.

Fixes angular#14321
juleskremer pushed a commit to juleskremer/angular that referenced this issue Aug 28, 2017
… component is dirty checked. (angular#16592)

Previously a projected view was only dirty checked when the
component in which it was inserted was dirty checked.

This fix changes the behavior so that a view is also dirty checked if
the declaring component is dirty checked.

Note: This does not change the order of change detection,
only the fact whether a projected view is dirty checked or not.

Fixes angular#14321
@tbosch tbosch removed this from Done in Compiler Oct 3, 2017
@robeverett
Copy link

I'm suffering from this in Angular 6.
What is the solution ?

Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'ngIf: '. Current value: 'ngIf: undefined'.
AppComponent.html:10
ERROR CONTEXT
AppComponent.html:10
DebugContext_ {view: Object, nodeIndex: 10, nodeDef: Object, elDef: Object, elView: Object}

@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 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants