The Default policy is: the ChangeDetectionStrategy. Default:
Implementation code:
/**
* Type of the Directive metadata.
*
* @publicApi* /
const Directive = makeDecorator('Directive', ɵ0$e, undefined.undefined, ɵ1$3);
const ɵ2$1 = (c = {}) = > (Object.assign({ changeDetection: ChangeDetectionStrategy. The Default}, c)), ɵ3$1 = (type, meta) = > SWITCH_COMPILE_COMPONENT(type, meta);
/**
* Component decorator and metadata.
*
* @Annotation
* @publicApi* /
const Component = makeDecorator('Component', ɵ2$1, Directive, undefined, ɵ3$1);
const ɵ4 = (p) = > (Object.assign({ pure: trueɵ}, p))5 = (type, meta) = > SWITCH_COMPILE_PIPE(type, meta);
/ * * *@Annotation
* @publicApi* /
const Pipe = makeDecorator('Pipe', ɵ4.undefined.undefined, ɵ5);
const ɵ6 = (bindingPropertyName) = > ({ bindingPropertyName });
/ * * *@Annotation
* @publicApi* /
const Input = makePropDecorator('Input', ɵ6);
const ɵ7 = (bindingPropertyName) = > ({ bindingPropertyName });
/ * * *@Annotation
* @publicApi* /
const Output = makePropDecorator('Output', ɵ7);
const ɵ8 = (hostPropertyName) = > ({ hostPropertyName });
/ * * *@Annotation
* @publicApi* /
const HostBinding = makePropDecorator('HostBinding', ɵ8);
const ɵ9 = (eventName, args) = > ({ eventName, args });
Copy the code
In SAP called Spartacus most Component, we will use @ Component changeDetection explicitly specified into ChangeDetectionStrategy. OnPush:
而OnPushIs another strategy for improving the performance of Angular applications.
In OnPush mode, only input ref change and Output’s call trigger the change detection mechanism.
TestBed. OverrideComponent provides a standard that covers ChangeDetectionStrategy mechanism.
More of Jerry’s original articles can be found in “Wang Zixi” :