Monday, June 7, 2021

ChangeDetectionStrategy

Change Detection means updating the view (DOM) when the data has changed.

 There are two types of change detection strategy 

1. OnPush

2. Default


OnPush :

Use the CheckOnce strategy, meaning that automatic change detection is deactivated until reactivated by setting the strategy to Default (CheckAlways). Change detection can still be explicitly invoked. This strategy applies to all child directives and cannot be overridden.

With onPush, the component only depends on its inputs and embraces the immutability, the change detection strategy will kicks in when:
  1. The Input reference changes;
  2. An event originated from the component or one of its children;
  3. Run change detection explicitly (componentRef.markForCheck());
  4. Use the async pipe in the view.

Default:

Use the default CheckAlways strategy, in which change detection is automatic until explicitly
 deactivated.

No comments:

Followers

Link