简体   繁体   中英

How to check which changedetectionStrategy is used in component

Is there a way to find out which changedetectionStrategy is actually used by components. I have a very large angular application which uses onPush on the outer component, so everything should use onPush.

But when applying onPush additionally on some of the child components, performance improves somehow.

That screenshot shows changeCycles when mouse moves in almost exact same time and distance.

左:没有额外的CD;右:额外的cd.onPush

The performance gain as you describe it makes sense: The outer components have ChangeDetectionStrategy.OnPush, so in a CD cycle they will only be checked in certain circumstances. But IF they are checked, CD is also performed on all children of such an OnPush component. If the children all have ChangeDetectionStrategy.Default, all of them (and their children, grandchildren, ...) will be checked for changes. If you mark some of the children as OnPush, they and and their children might be skipped during a CD cycle.

You can visualize this process in the AngularDevTools by choosing the flame graph and selecting to only show the components that have been checked during a cycle:

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM