Using ChangeDetectionStrategy.Default component inside branch of ChangeDetectionStrategy.OnPush components

160 views Asked by At

Is it acceptable to use component with Default change detection strategy inside of branch with components, which defined with OnPush change detection strategy?

Let's assume that have OnPush component which have some hierarchy of component, which are also OnPush. But we need to add reusable component, which shows for example current time, somewhere in the bottom of this hierarchy.

To make time component work, I have to use changeDetectionRef.markForCheck in it, which actually force angular to check all ancestors of this component.

Is a good practice to do it? Any possible ways to avoid it?

I understand that I could move my change time logic to the top component, and pass down current time value, but I don't want to do that, because this component is reusable and I have to duplicate this logic in a few places, and also it's a too big way from top component to this.

0

There are 0 answers