File tree Expand file tree Collapse file tree 2 files changed +9
-6
lines changed
adev/src/content/guide/components
packages/core/src/change_detection Expand file tree Collapse file tree 2 files changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -108,19 +108,20 @@ mapping each component input name to a `SimpleChange` object. Each `SimpleChange
108108input's previous value, its current value, and a flag for whether this is the first time the input
109109has 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})
115117export 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}
Original file line number Diff line number Diff 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 */
4446export type SimpleChanges < T = unknown > = T extends object
You can’t perform that action at this time.
0 commit comments