Skip to content

Commit 43ef717

Browse files
SkyZeroZxpkozlowski-opensource
authored andcommitted
docs: update change detection strategy references
1 parent c1261b0 commit 43ef717

8 files changed

Lines changed: 10 additions & 28 deletions

File tree

adev/src/content/best-practices/runtime-performance/skipping-subtrees.md

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,20 @@ JavaScript, by default, uses mutable data structures that you can reference from
44

55
Change detection is sufficiently fast for most applications. However, when an application has an especially large component tree, running change detection across the whole application can cause performance issues. You can address this by configuring change detection to only run on a subset of the component tree.
66

7-
If you are confident that a part of the application is not affected by a state change, you can use [OnPush](/api/core/ChangeDetectionStrategy) to skip change detection in an entire component subtree.
8-
97
## Using `OnPush`
108

11-
OnPush change detection instructs Angular to run change detection for a component subtree **only** when:
9+
OnPush is the default change detection strategy in Angular (since v22). It instructs Angular to run change detection for a component subtree **only** when:
1210

1311
- The root component of the subtree receives new inputs as the result of a template binding. Angular compares the current and past value of the input with `==`.
1412
- Angular handles an event _(for example using event binding, output binding, or `@HostListener` )_ in the subtree's root component or any of its children whether they are using OnPush change detection or not.
1513

16-
You can set the change detection strategy of a component to `OnPush` in the `@Component` decorator:
17-
18-
```ts
19-
import {ChangeDetectionStrategy, Component} from '@angular/core';
20-
21-
@Component({
22-
changeDetection: ChangeDetectionStrategy.OnPush,
23-
})
24-
export class MyComponent {}
25-
```
26-
2714
## Common change detection scenarios
2815

2916
This section examines several common change detection scenarios to illustrate Angular's behavior.
3017

31-
### An event is handled by a component with default change detection
18+
### An event is handled by a component with `Eager` change detection
3219

33-
If Angular handles an event within a component without `OnPush` strategy, the framework executes change detection on the entire component tree. Angular will skip descendant component subtrees with roots using `OnPush`, which have not received new inputs.
20+
If Angular handles an event within a component with the `Eager` strategy, the framework executes change detection on the entire component tree. Angular will skip descendant component subtrees with roots using `OnPush`, which have not received new inputs.
3421

3522
As an example, if we set the change detection strategy of `MainComponent` to `OnPush` and the user interacts with a component outside the subtree with root `MainComponent`, Angular will check all the pink components from the diagram below (`AppComponent`, `HeaderComponent`, `SearchComponent`, `ButtonComponent`) unless `MainComponent` receives new inputs:
3623

adev/src/content/guide/components/advanced-configuration.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ TIP: This guide assumes you've already read the [Essentials Guide](essentials).
77
The `@Component` decorator accepts a `changeDetection` option that controls the component's **change
88
detection mode**. There are two change detection mode options.
99

10-
**`ChangeDetectionStrategy.Eager`/`Default`** is, unsurprisingly, the default strategy. In this mode,
10+
**`ChangeDetectionStrategy.Eager`/`Default`** is an optional mode. In this mode,
1111
Angular checks whether the component's DOM needs an update whenever any activity may have occurred
1212
application-wide. Activities that trigger this checking include user interaction, network response,
1313
timers, and more.
1414

15-
**`ChangeDetectionStrategy.OnPush`** is an optional mode that reduces the amount of checking Angular
15+
**`ChangeDetectionStrategy.OnPush`** is the default strategy (since v22). This mode reduces the amount of checking Angular
1616
needs to perform. In this mode, the framework only checks if a component's DOM needs an update when:
1717

1818
- A component input has changes as a result of a binding in a template, or

adev/src/content/tutorials/signals/steps/1-creating-your-first-signal/README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,3 @@ The toggle button is already in the template. Connect it to your `toggleStatus()
116116
Congratulations! You've created your first signal and learned how to update it using both `set()` and `update()` methods. The `signal()` function creates a reactive value that Angular tracks, and when you update it, your UI automatically reflects the changes.
117117

118118
Next, you'll learn [how to derive state from signals using computed](/tutorials/signals/2-deriving-state-with-computed-signals)!
119-
120-
<docs-callout helpful title="About ChangeDetectionStrategy.OnPush">
121-
122-
You might notice `ChangeDetectionStrategy.OnPush` in the component decorator throughout this tutorial. This is a performance optimization for Angular components that use signals. For now, you can safely ignore it—just know it helps your app run faster when using signals! You can learn more in the [change detection strategies API docs](/api/core/ChangeDetectionStrategy).
123-
124-
</docs-callout>

adev/src/context/airules.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ Here is a link to the most recent Angular style guide https://angular.dev/style-
8686
- Use `input()` signal instead of decorators, learn more here https://angular.dev/guide/components/inputs
8787
- Use `output()` function instead of decorators, learn more here https://angular.dev/guide/components/outputs
8888
- Use `computed()` for derived state learn more about signals here https://angular.dev/guide/signals.
89-
- Set `changeDetection: ChangeDetectionStrategy.OnPush` in `@Component` decorator
9089
- Prefer inline templates for small components
9190
- Prefer Reactive forms instead of Template-driven ones
9291
- Do NOT use `ngClass`, use `class` bindings instead, for context: https://angular.dev/guide/templates/binding#css-class-and-style-property-bindings

adev/src/context/angular-20.mdc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ This project adheres to modern Angular best practices, emphasizing maintainabili
6464
userSelected = output<string>();
6565
```
6666
* **`computed()` for Derived State:** Use the `computed()` function from `@angular/core` for derived state based on signals.
67-
* **`ChangeDetectionStrategy.OnPush`:** Always set `changeDetection: ChangeDetectionStrategy.OnPush` in the `@Component` decorator for performance benefits by reducing unnecessary change detection cycles.
6867
* **Inline Templates:** Prefer inline templates (template: `...`) for small components to keep related code together. For larger templates, use external HTML files.
6968
* **Reactive Forms:** Prefer Reactive forms over Template-driven forms for complex forms, validation, and dynamic controls due to their explicit, immutable, and synchronous nature.
7069
* **No `ngClass` / `NgClass`:** Do not use the `ngClass` directive. Instead, use native `class` bindings for conditional styling.

adev/src/context/guidelines.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ Here is a link to the most recent Angular style guide https://angular.dev/style-
9292
- Use `input()` signal instead of decorators, learn more here https://angular.dev/guide/components/inputs
9393
- Use `output()` function instead of decorators, learn more here https://angular.dev/guide/components/outputs
9494
- Use `computed()` for derived state learn more about signals here https://angular.dev/guide/signals.
95-
- Set `changeDetection: ChangeDetectionStrategy.OnPush` in `@Component` decorator
9695
- Prefer inline templates for small components
9796
- Prefer Reactive forms instead of Template-driven ones
9897
- Do NOT use `ngClass`, use `class` bindings instead, for context: https://angular.dev/guide/templates/binding#css-class-and-style-property-bindings

packages/core/src/change_detection/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ export enum ChangeDetectionStrategy {
2121
* until reactivated by setting the strategy to `Default` (`CheckAlways`).
2222
* Change detection can still be explicitly invoked.
2323
* This strategy applies to all child directives and cannot be overridden.
24+
*
25+
* NOTE: OnPush is enabled by default.
2426
*/
2527
OnPush = 0,
2628

packages/core/src/metadata/directives.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,9 @@ export interface Component extends Directive {
548548
* which is responsible for propagating the component's bindings.
549549
* The strategy is one of:
550550
* - `ChangeDetectionStrategy#OnPush` sets the strategy to `CheckOnce` (on demand).
551-
* - `ChangeDetectionStrategy#Default` sets the strategy to `CheckAlways`.
551+
* - `ChangeDetectionStrategy#Eager` sets the strategy to `CheckAlways`.
552+
*
553+
* NOTE: OnPush is enabled by default.
552554
*/
553555
changeDetection?: ChangeDetectionStrategy;
554556

0 commit comments

Comments
 (0)