Sobes.tech
Middle

The parent component uses the OnPush strategy, and the child component uses Default. What happens to the child component when changes occur? In which direction does change detection run — from top to bottom or bottom to top?

sobes.tech AI

Answer from AI

When the parent component uses the OnPush change detection strategy, and the child uses the Default strategy, the behavior is as follows:

  • The parent component will be checked by Angular only when its input data changes or an event occurs within the component.
  • The child component with the Default strategy is checked during every change detection cycle if it is in the component tree that Angular checks.

Change detection in Angular proceeds from top to bottom through the component tree. This means the parent component is checked first, then its children.

If the parent component has not changed (OnPush and input data unchanged), Angular will not check its child components, even if the child has the Default strategy.

Therefore, a child component with the Default strategy will only be checked if the parent component is marked for checking (for example, input data changed or detectChanges was called).

Summary:

  • Change detection proceeds from top to bottom.
  • OnPush in the parent limits the checking of child components.
  • Default in the child component will not cause Angular to check it if the parent is not checked.
The parent component uses the OnPush strategy, and… - sobes.tech