Skip to content

Commit c185c53

Browse files
authored
docs: Fix usage of effect in examples (angular#29305)
Ensure that `effect` code that emits on public rxjs streams is run as untracked.
1 parent 5da528e commit c185c53

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/components-examples/material/form-field/form-field-custom-control/form-field-custom-control-example.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
input,
1414
model,
1515
signal,
16+
untracked,
1617
viewChild,
1718
} from '@angular/core';
1819
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
@@ -175,19 +176,20 @@ export class MyTelInput implements ControlValueAccessor, MatFormFieldControl<MyT
175176
this._required();
176177
this._disabled();
177178
// Propagate state changes.
178-
this.stateChanges.next();
179+
untracked(() => this.stateChanges.next());
179180
});
180181

181182
effect(() => {
182183
if (this._disabled()) {
183-
this.parts.disable();
184+
untracked(() => this.parts.disable());
184185
} else {
185-
this.parts.enable();
186+
untracked(() => this.parts.enable());
186187
}
187188
});
188189

189190
effect(() => {
190-
this.parts.setValue(this._value() || new MyTel('', '', ''));
191+
const value = this._value() || new MyTel('', '', '');
192+
untracked(() => this.parts.setValue(value));
191193
});
192194

193195
this.parts.statusChanges.pipe(takeUntilDestroyed()).subscribe(() => {

0 commit comments

Comments
 (0)