I use Angular 9
I have Parent and Child components and service which stores BehaviorSubject
. All components have OnPush
strategy
- Parent component uses async pipe to subscribe on that service subject
- Parent component contains child component
- Child component changes that service subject at the beginning of its lifecycle (ngOnInit)
With this steps parent will not react immediately after child changes the observable. Here is reproducible demo . Parent will not be updated until you focus input of a child, for instance.
I have debugged the process and see that tick
function is called after async pipe does markForCheck
. So I cannot understand why then the view is not updated?
I notice that if I Change strategy back to Default
the ExpressionChangedAfterItHasBeenCheckedError
will appear, so it looks like that this change happens outside of main Change Detection process.
Can you help me what is the problem with current approach and what is the correct way to make changes like I described?