8000 OnPush change detection doesn't work for outputs emitted from lifecycle callbacks · Issue #24965 · angular/angular · GitHub
[go: up one dir, main page]

Skip to content
OnPush change detection doesn't work for outputs emitted from lifecycle callbacks #24965
Closed
@sebek64

Description

@sebek64

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[X] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
[ ] Other... Please describe:

Current behavior

This issue is related to the closed issue #24690 for which I managed to create a simple repro case. Complete description follows.

When a component with OnPush change detection subscribes an output of a subcomponent, it works pretty well, unless this subcomponent emits values from the initialization lifecycle callbacks (ngOnInit, ngAfterViewInit). Then, no change detection is performed, and even calling changeDetectorRef.markForCheck() doesn't help. Only calling detectChanges() manually works.

Quite surprisingly, when the value is emitted from ngOnInit, it is shown in the interpolation strings, but not passed to subcomponents. On the other hand, ngAfterViewInit value is not used at all.

Expected behavior

It should work out of the box, without the need to work with change detector manually. If this is not supported for some architectural reason, the documentation should contain a big warning about it.

Minimal reproduction of the problem with instructions

I've prepared a git repo here: https://github.com/sebek64/angular-issue-repro

The initial commit is a plain angular-cli project. The next commit adds the repro code. Run via "yarn start", open the browser, and you should see output like this:

outer component value: "emitted value from ngOnInit"
inside subcomponent: ""
Button

When the button is clicked, the output changes to

outer component value: "Emitted value from button"
inside subcomponent: "Emitted value from button"
Button

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

Environment


Angular version: 6.0.9


Browser:
- [X] Chrome (desktop) version 67.0.3396.99
- [X] Firefox version 52.9.0
- Platform:  Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0