Change default change detection strategy

How to set default change detection strategy on OnPush ? Is it possible to somehow install it globally?

I want to avoid adding this line to every component

 @Component({ ... changeDetection: ChangeDetectionStrategy.OnPush, ... }) 
+12
source share
2 answers

A change detection strategy can only be defined for each component or directive not globally.

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

+11
source

Unable to set global ChangeDetection.

However, it can be installed in the CLI, so that all components newly generated using the ng generate component (or ng gc ) will be set to OnPush .

Run this command to install it:

 ng config schematics.@schematics /angular.component.changeDetection OnPush 

Alternatively (this is what this command does), add this block at the basic level of your angular.json :

 // angular.json { //... "schematics": { "@schematics/angular": { "component": { "changeDetection": "OnPush" } } } } 
0
source

All Articles