Search code examples
angularangular-changedetection

Change default change detection strategy


How to set the default change detection strategy to OnPush? Can it be set globally somehow?

I want to avoid having to adding this line to every component

@Component({
    ...
    changeDetection: ChangeDetectionStrategy.OnPush,
    ...
})

Solution

  • The change detection strategy can only be defined per component or directive not globally.

    Using a custom decorator is discouraged because it will not be supported by the upcoming offline template compiler.