MCPcopy Create free account
hub / github.com/angular/angular / setUpModelChangePipeline

Function setUpModelChangePipeline

packages/forms/src/directives/shared.ts:292–307  ·  view source on GitHub ↗
(control: FormControl, dir: NgControl)

Source from the content-addressed store, hash-verified

290}
291
292function setUpModelChangePipeline(control: FormControl, dir: NgControl): void {
293 const onChange = (newValue?: any, emitModelEvent?: boolean) => {
294 // control -> view
295 dir.valueAccessor!.writeValue(newValue);
296
297 // control -> ngModel
298 if (emitModelEvent) dir.viewToModelUpdate(newValue);
299 };
300 control.registerOnChange(onChange);
301
302 // Register a callback function to cleanup onChange handler
303 // from a control instance when a directive is destroyed.
304 dir._registerOnDestroy(() => {
305 control._unregisterOnChange(onChange);
306 });
307}
308
309/**
310 * Links a FormGroup or FormArray instance and corresponding Form directive by setting up validators

Callers 1

Calls 2

registerOnChangeMethod · 0.65
_unregisterOnChangeMethod · 0.65

Tested by

no test coverage detected