Skip to content

Commit e9ba63a

Browse files
SkyZeroZxthePunderWoman
authored andcommitted
docs: Adds documentation for generic type argument to SimpleChanges
1 parent 0bb09dc commit e9ba63a

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

adev/src/content/guide/components/lifecycle.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,19 +108,20 @@ mapping each component input name to a `SimpleChange` object. Each `SimpleChange
108108
input's previous value, its current value, and a flag for whether this is the first time the input
109109
has changed.
110110

111+
You can optionally pass the current class or this as the first generic argument for stronger type checking.
112+
111113
```ts
112114
@Component({
113115
/* ... */
114116
})
115117
export class UserProfile {
116118
name = input('');
117119

118-
ngOnChanges(changes: SimpleChanges) {
119-
for (const inputName in changes) {
120-
const inputValues = changes[inputName];
121-
console.log(`Previous ${inputName} == ${inputValues.previousValue}`);
122-
console.log(`Current ${inputName} == ${inputValues.currentValue}`);
123-
console.log(`Is first ${inputName} change == ${inputValues.firstChange}`);
120+
ngOnChanges(changes: SimpleChanges<UserProfile>) {
121+
if (changes.name) {
122+
console.log(`Previous: ${changes.name.previousValue}`);
123+
console.log(`Current: ${changes.name.currentValue}`);
124+
console.log(`Is first ${changes.name.firstChange}`);
124125
}
125126
}
126127
}

packages/core/src/change_detection/simple_change.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ export class SimpleChange<T = any> {
3939
*
4040
* @see {@link OnChanges}
4141
*
42+
* @see [Inspecting changes](guide/components/lifecycle#inspecting-changes)
43+
*
4244
* @publicApi
4345
*/
4446
export type SimpleChanges<T = unknown> = T extends object

0 commit comments

Comments
 (0)