“Change Detection”?
Change Detection means updating the view (DOM) when the data has changed.
Change Detection is done in two steps
Angular provides you two Change Detection Strategies, the default one and the onPush.
In order to understand the difference between a Subject and an Observable, you need to be aware of two distinct concepts
– A data producer
– A data consumer
Change Detection means updating the view (DOM) when the data has changed.
Change Detection is done in two steps
- Update the application model (developer);
- Reflect the state of the model in the view (Angular).
If we take a todo application, represented by the graphic above. We have a fairly simple application that has a
TodosComponent
managing a list of TodoComponent
. If we modify this list, by changing the value of the first item of the todos’ list (in yellow), we will have the following flow:- The developer is making changes to the model (like a component’s bindings);
- Angular’s change detection kicks in to propagate the changes;
- Change detection goes through every components in the component tree (from top to bottom) to check if the model it depends on changed;
- If Yes, it will update the component;
- Angular updates the component’s view (DOM).
The way Angular runs the change detection by starting from the top and continuing until it reaches the bottom, makes the system more predictable and more performant.
Angular Change Detection Strategies
ChangeDetectionStrategy.Default
By default, Angular has to be conservative and will checks every time something may have changed, this is called dirty checking.
ChangeDetectionStrategy.onPush
With onPush, Angular will only depend on the component’s inputs, events, markForCheck method, or the use of the async pipe in the template, to perform a change detection mechanism and update the view.
In order to understand the difference between a Subject and an Observable, you need to be aware of two distinct concepts
– A data producer
– A data consumer
Angular switch map and merge map
Rx js debounce and total
diff between observable and subject
weekset and set
Angular change detection
array fill
Great post.
ReplyDeleteform.jotform.com
ReplyDeleteExcellent idea!!! I really enjoyed reading your post. Thank you for your efforts. Share more like this
Data Science
Big Data