MCPcopy Index your code
hub / github.com/angular/angular / setControl

Method setControl

packages/forms/src/model/form_array.ts:258–274  ·  view source on GitHub ↗

* Replace an existing control. * * @param index Index in the array to replace the control. If `index` is negative, wraps around * from the back. If `index` is greatly negative (less than `-length`), replaces the first * element. This behavior is the same as `Array.splice(index, 1

(index: number, control: TControl, options: {emitEvent?: boolean} = {})

Source from the content-addressed store, hash-verified

256 * replaced with a new one. When false, no events are emitted.
257 */
258 setControl(index: number, control: TControl, options: {emitEvent?: boolean} = {}): void {
259 // Adjust the index, then clamp it at no less than 0 to prevent undesired underflows.
260 let adjustedIndex = this._adjustIndex(index);
261 if (adjustedIndex < 0) adjustedIndex = 0;
262
263 if (this.controls[adjustedIndex])
264 this.controls[adjustedIndex]._registerOnCollectionChange(() => {});
265 this.controls.splice(adjustedIndex, 1);
266
267 if (control) {
268 this.controls.splice(adjustedIndex, 0, control);
269 this._registerControl(control);
270 }
271
272 this.updateValueAndValidity({emitEvent: options.emitEvent});
273 this._onCollectionChange();
274 }
275
276 /**
277 * Length of the control array.

Callers

nothing calls this directly

Calls 3

_adjustIndexMethod · 0.95
_registerControlMethod · 0.95

Tested by

no test coverage detected