1
|
import { Observable } from 'rxjs/Observable';
|
2
|
import { AsyncValidatorFn, ValidationErrors, ValidatorFn } from './directives/validators';
|
3
|
/**
|
4
|
* Indicates that a FormControl is valid, i.e. that no errors exist in the input value.
|
5
|
*/
|
6
|
export declare const VALID = "VALID";
|
7
|
/**
|
8
|
* Indicates that a FormControl is invalid, i.e. that an error exists in the input value.
|
9
|
*/
|
10
|
export declare const INVALID = "INVALID";
|
11
|
/**
|
12
|
* Indicates that a FormControl is pending, i.e. that async validation is occurring and
|
13
|
* errors are not yet available for the input value.
|
14
|
*/
|
15
|
export declare const PENDING = "PENDING";
|
16
|
/**
|
17
|
* Indicates that a FormControl is disabled, i.e. that the control is exempt from ancestor
|
18
|
* calculations of validity or value.
|
19
|
*/
|
20
|
export declare const DISABLED = "DISABLED";
|
21
|
/**
|
22
|
* @whatItDoes This is the base class for {@link FormControl}, {@link FormGroup}, and
|
23
|
* {@link FormArray}.
|
24
|
*
|
25
|
* It provides some of the shared behavior that all controls and groups of controls have, like
|
26
|
* running validators, calculating status, and resetting state. It also defines the properties
|
27
|
* that are shared between all sub-classes, like `value`, `valid`, and `dirty`. It shouldn't be
|
28
|
* instantiated directly.
|
29
|
*
|
30
|
* @stable
|
31
|
*/
|
32
|
export declare abstract class AbstractControl {
|
33
|
validator: ValidatorFn | null;
|
34
|
asyncValidator: AsyncValidatorFn | null;
|
35
|
private _valueChanges;
|
36
|
private _statusChanges;
|
37
|
private _status;
|
38
|
private _errors;
|
39
|
private _pristine;
|
40
|
private _touched;
|
41
|
private _parent;
|
42
|
private _asyncValidationSubscription;
|
43
|
constructor(validator: ValidatorFn | null, asyncValidator: AsyncValidatorFn | null);
|
44
|
/**
|
45
|
* The value of the control.
|
46
|
*/
|
47
|
readonly value: any;
|
48
|
/**
|
49
|
* The parent control.
|
50
|
*/
|
51
|
readonly parent: FormGroup | FormArray;
|
52
|
/**
|
53
|
* The validation status of the control. There are four possible
|
54
|
* validation statuses:
|
55
|
*
|
56
|
* * **VALID**: control has passed all validation checks
|
57
|
* * **INVALID**: control has failed at least one validation check
|
58
|
* * **PENDING**: control is in the midst of conducting a validation check
|
59
|
* * **DISABLED**: control is exempt from validation checks
|
60
|
*
|
61
|
* These statuses are mutually exclusive, so a control cannot be
|
62
|
* both valid AND invalid or invalid AND disabled.
|
63
|
*/
|
64
|
readonly status: string;
|
65
|
/**
|
66
|
* A control is `valid` when its `status === VALID`.
|
67
|
*
|
68
|
* In order to have this status, the control must have passed all its
|
69
|
* validation checks.
|
70
|
*/
|
71
|
readonly valid: boolean;
|
72
|
/**
|
73
|
* A control is `invalid` when its `status === INVALID`.
|
74
|
*
|
75
|
* In order to have this status, the control must have failed
|
76
|
* at least one of its validation checks.
|
77
|
*/
|
78
|
readonly invalid: boolean;
|
79
|
/**
|
80
|
* A control is `pending` when its `status === PENDING`.
|
81
|
*
|
82
|
* In order to have this status, the control must be in the
|
83
|
* middle of conducting a validation check.
|
84
|
*/
|
85
|
readonly pending: boolean;
|
86
|
/**
|
87
|
* A control is `disabled` when its `status === DISABLED`.
|
88
|
*
|
89
|
* Disabled controls are exempt from validation checks and
|
90
|
* are not included in the aggregate value of their ancestor
|
91
|
* controls.
|
92
|
*/
|
93
|
readonly disabled: boolean;
|
94
|
/**
|
95
|
* A control is `enabled` as long as its `status !== DISABLED`.
|
96
|
*
|
97
|
* In other words, it has a status of `VALID`, `INVALID`, or
|
98
|
* `PENDING`.
|
99
|
*/
|
100
|
readonly enabled: boolean;
|
101
|
/**
|
102
|
* Returns any errors generated by failing validation. If there
|
103
|
* are no errors, it will return null.
|
104
|
*/
|
105
|
readonly errors: ValidationErrors | null;
|
106
|
/**
|
107
|
* A control is `pristine` if the user has not yet changed
|
108
|
* the value in the UI.
|
109
|
*
|
110
|
* Note that programmatic changes to a control's value will
|
111
|
* *not* mark it dirty.
|
112
|
*/
|
113
|
readonly pristine: boolean;
|
114
|
/**
|
115
|
* A control is `dirty` if the user has changed the value
|
116
|
* in the UI.
|
117
|
*
|
118
|
* Note that programmatic changes to a control's value will
|
119
|
* *not* mark it dirty.
|
120
|
*/
|
121
|
readonly dirty: boolean;
|
122
|
/**
|
123
|
* A control is marked `touched` once the user has triggered
|
124
|
* a `blur` event on it.
|
125
|
*/
|
126
|
readonly touched: boolean;
|
127
|
/**
|
128
|
* A control is `untouched` if the user has not yet triggered
|
129
|
* a `blur` event on it.
|
130
|
*/
|
131
|
readonly untouched: boolean;
|
132
|
/**
|
133
|
* Emits an event every time the value of the control changes, in
|
134
|
* the UI or programmatically.
|
135
|
*/
|
136
|
readonly valueChanges: Observable<any>;
|
137
|
/**
|
138
|
* Emits an event every time the validation status of the control
|
139
|
* is re-calculated.
|
140
|
*/
|
141
|
readonly statusChanges: Observable<any>;
|
142
|
/**
|
143
|
* Sets the synchronous validators that are active on this control. Calling
|
144
|
* this will overwrite any existing sync validators.
|
145
|
*/
|
146
|
setValidators(newValidator: ValidatorFn | ValidatorFn[] | null): void;
|
147
|
/**
|
148
|
* Sets the async validators that are active on this control. Calling this
|
149
|
* will overwrite any existing async validators.
|
150
|
*/
|
151
|
setAsyncValidators(newValidator: AsyncValidatorFn | AsyncValidatorFn[]): void;
|
152
|
/**
|
153
|
* Empties out the sync validator list.
|
154
|
*/
|
155
|
clearValidators(): void;
|
156
|
/**
|
157
|
* Empties out the async validator list.
|
158
|
*/
|
159
|
clearAsyncValidators(): void;
|
160
|
/**
|
161
|
* Marks the control as `touched`.
|
162
|
*
|
163
|
* This will also mark all direct ancestors as `touched` to maintain
|
164
|
* the model.
|
165
|
*/
|
166
|
markAsTouched(opts?: {
|
167
|
onlySelf?: boolean;
|
168
|
}): void;
|
169
|
/**
|
170
|
* Marks the control as `untouched`.
|
171
|
*
|
172
|
* If the control has any children, it will also mark all children as `untouched`
|
173
|
* to maintain the model, and re-calculate the `touched` status of all parent
|
174
|
* controls.
|
175
|
*/
|
176
|
markAsUntouched(opts?: {
|
177
|
onlySelf?: boolean;
|
178
|
}): void;
|
179
|
/**
|
180
|
* Marks the control as `dirty`.
|
181
|
*
|
182
|
* This will also mark all direct ancestors as `dirty` to maintain
|
183
|
* the model.
|
184
|
*/
|
185
|
markAsDirty(opts?: {
|
186
|
onlySelf?: boolean;
|
187
|
}): void;
|
188
|
/**
|
189
|
* Marks the control as `pristine`.
|
190
|
*
|
191
|
* If the control has any children, it will also mark all children as `pristine`
|
192
|
* to maintain the model, and re-calculate the `pristine` status of all parent
|
193
|
* controls.
|
194
|
*/
|
195
|
markAsPristine(opts?: {
|
196
|
onlySelf?: boolean;
|
197
|
}): void;
|
198
|
/**
|
199
|
* Marks the control as `pending`.
|
200
|
*/
|
201
|
markAsPending(opts?: {
|
202
|
onlySelf?: boolean;
|
203
|
}): void;
|
204
|
/**
|
205
|
* Disables the control. This means the control will be exempt from validation checks and
|
206
|
* excluded from the aggregate value of any parent. Its status is `DISABLED`.
|
207
|
*
|
208
|
* If the control has children, all children will be disabled to maintain the model.
|
209
|
*/
|
210
|
disable(opts?: {
|
211
|
onlySelf?: boolean;
|
212
|
emitEvent?: boolean;
|
213
|
}): void;
|
214
|
/**
|
215
|
* Enables the control. This means the control will be included in validation checks and
|
216
|
* the aggregate value of its parent. Its status is re-calculated based on its value and
|
217
|
* its validators.
|
218
|
*
|
219
|
* If the control has children, all children will be enabled.
|
220
|
*/
|
221
|
enable(opts?: {
|
222
|
onlySelf?: boolean;
|
223
|
emitEvent?: boolean;
|
224
|
}): void;
|
225
|
private _updateAncestors(onlySelf);
|
226
|
setParent(parent: FormGroup | FormArray): void;
|
227
|
/**
|
228
|
* Sets the value of the control. Abstract method (implemented in sub-classes).
|
229
|
*/
|
230
|
abstract setValue(value: any, options?: Object): void;
|
231
|
/**
|
232
|
* Patches the value of the control. Abstract method (implemented in sub-classes).
|
233
|
*/
|
234
|
abstract patchValue(value: any, options?: Object): void;
|
235
|
/**
|
236
|
* Resets the control. Abstract method (implemented in sub-classes).
|
237
|
*/
|
238
|
abstract reset(value?: any, options?: Object): void;
|
239
|
/**
|
240
|
* Re-calculates the value and validation status of the control.
|
241
|
*
|
242
|
* By default, it will also update the value and validity of its ancestors.
|
243
|
*/
|
244
|
updateValueAndValidity(opts?: {
|
245
|
onlySelf?: boolean;
|
246
|
emitEvent?: boolean;
|
247
|
}): void;
|
248
|
private _setInitialStatus();
|
249
|
private _runValidator();
|
250
|
private _runAsyncValidator(emitEvent?);
|
251
|
private _cancelExistingSubscription();
|
252
|
/**
|
253
|
* Sets errors on a form control.
|
254
|
*
|
255
|
* This is used when validations are run manually by the user, rather than automatically.
|
256
|
*
|
257
|
* Calling `setErrors` will also update the validity of the parent control.
|
258
|
*
|
259
|
* ### Example
|
260
|
*
|
261
|
* ```
|
262
|
* const login = new FormControl("someLogin");
|
263
|
* login.setErrors({
|
264
|
* "notUnique": true
|
265
|
* });
|
266
|
*
|
267
|
* expect(login.valid).toEqual(false);
|
268
|
* expect(login.errors).toEqual({"notUnique": true});
|
269
|
*
|
270
|
* login.setValue("someOtherLogin");
|
271
|
*
|
272
|
* expect(login.valid).toEqual(true);
|
273
|
* ```
|
274
|
*/
|
275
|
setErrors(errors: ValidationErrors | null, opts?: {
|
276
|
emitEvent?: boolean;
|
277
|
}): void;
|
278
|
/**
|
279
|
* Retrieves a child control given the control's name or path.
|
280
|
*
|
281
|
* Paths can be passed in as an array or a string delimited by a dot.
|
282
|
*
|
283
|
* To get a control nested within a `person` sub-group:
|
284
|
*
|
285
|
* * `this.form.get('person.name');`
|
286
|
*
|
287
|
* -OR-
|
288
|
*
|
289
|
* * `this.form.get(['person', 'name']);`
|
290
|
*/
|
291
|
get(path: Array<string | number> | string): AbstractControl | null;
|
292
|
/**
|
293
|
* Returns error data if the control with the given path has the error specified. Otherwise
|
294
|
* returns null or undefined.
|
295
|
*
|
296
|
* If no path is given, it checks for the error on the present control.
|
297
|
*/
|
298
|
getError(errorCode: string, path?: string[]): any;
|
299
|
/**
|
300
|
* Returns true if the control with the given path has the error specified. Otherwise
|
301
|
* returns false.
|
302
|
*
|
303
|
* If no path is given, it checks for the error on the present control.
|
304
|
*/
|
305
|
hasError(errorCode: string, path?: string[]): boolean;
|
306
|
/**
|
307
|
* Retrieves the top-level ancestor of this control.
|
308
|
*/
|
309
|
readonly root: AbstractControl;
|
310
|
private _calculateStatus();
|
311
|
}
|
312
|
/**
|
313
|
* @whatItDoes Tracks the value and validation status of an individual form control.
|
314
|
*
|
315
|
* It is one of the three fundamental building blocks of Angular forms, along with
|
316
|
* {@link FormGroup} and {@link FormArray}.
|
317
|
*
|
318
|
* @howToUse
|
319
|
*
|
320
|
* When instantiating a {@link FormControl}, you can pass in an initial value as the
|
321
|
* first argument. Example:
|
322
|
*
|
323
|
* ```ts
|
324
|
* const ctrl = new FormControl('some value');
|
325
|
* console.log(ctrl.value); // 'some value'
|
326
|
*```
|
327
|
*
|
328
|
* You can also initialize the control with a form state object on instantiation,
|
329
|
* which includes both the value and whether or not the control is disabled.
|
330
|
* You can't use the value key without the disabled key; both are required
|
331
|
* to use this way of initialization.
|
332
|
*
|
333
|
* ```ts
|
334
|
* const ctrl = new FormControl({value: 'n/a', disabled: true});
|
335
|
* console.log(ctrl.value); // 'n/a'
|
336
|
* console.log(ctrl.status); // 'DISABLED'
|
337
|
* ```
|
338
|
*
|
339
|
* To include a sync validator (or an array of sync validators) with the control,
|
340
|
* pass it in as the second argument. Async validators are also supported, but
|
341
|
* have to be passed in separately as the third arg.
|
342
|
*
|
343
|
* ```ts
|
344
|
* const ctrl = new FormControl('', Validators.required);
|
345
|
* console.log(ctrl.value); // ''
|
346
|
* console.log(ctrl.status); // 'INVALID'
|
347
|
* ```
|
348
|
*
|
349
|
* See its superclass, {@link AbstractControl}, for more properties and methods.
|
350
|
*
|
351
|
* * **npm package**: `@angular/forms`
|
352
|
*
|
353
|
* @stable
|
354
|
*/
|
355
|
export declare class FormControl extends AbstractControl {
|
356
|
constructor(formState?: any, validator?: ValidatorFn | ValidatorFn[] | null, asyncValidator?: AsyncValidatorFn | AsyncValidatorFn[] | null);
|
357
|
/**
|
358
|
* Set the value of the form control to `value`.
|
359
|
*
|
360
|
* If `onlySelf` is `true`, this change will only affect the validation of this `FormControl`
|
361
|
* and not its parent component. This defaults to false.
|
362
|
*
|
363
|
* If `emitEvent` is `true`, this
|
364
|
* change will cause a `valueChanges` event on the `FormControl` to be emitted. This defaults
|
365
|
* to true (as it falls through to `updateValueAndValidity`).
|
366
|
*
|
367
|
* If `emitModelToViewChange` is `true`, the view will be notified about the new value
|
368
|
* via an `onChange` event. This is the default behavior if `emitModelToViewChange` is not
|
369
|
* specified.
|
370
|
*
|
371
|
* If `emitViewToModelChange` is `true`, an ngModelChange event will be fired to update the
|
372
|
* model. This is the default behavior if `emitViewToModelChange` is not specified.
|
373
|
*/
|
374
|
setValue(value: any, options?: {
|
375
|
onlySelf?: boolean;
|
376
|
emitEvent?: boolean;
|
377
|
emitModelToViewChange?: boolean;
|
378
|
emitViewToModelChange?: boolean;
|
379
|
}): void;
|
380
|
/**
|
381
|
* Patches the value of a control.
|
382
|
*
|
383
|
* This function is functionally the same as {@link FormControl#setValue} at this level.
|
384
|
* It exists for symmetry with {@link FormGroup#patchValue} on `FormGroups` and `FormArrays`,
|
385
|
* where it does behave differently.
|
386
|
*/
|
387
|
patchValue(value: any, options?: {
|
388
|
onlySelf?: boolean;
|
389
|
emitEvent?: boolean;
|
390
|
emitModelToViewChange?: boolean;
|
391
|
emitViewToModelChange?: boolean;
|
392
|
}): void;
|
393
|
/**
|
394
|
* Resets the form control. This means by default:
|
395
|
*
|
396
|
* * it is marked as `pristine`
|
397
|
* * it is marked as `untouched`
|
398
|
* * value is set to null
|
399
|
*
|
400
|
* You can also reset to a specific form state by passing through a standalone
|
401
|
* value or a form state object that contains both a value and a disabled state
|
402
|
* (these are the only two properties that cannot be calculated).
|
403
|
*
|
404
|
* Ex:
|
405
|
*
|
406
|
* ```ts
|
407
|
* this.control.reset('Nancy');
|
408
|
*
|
409
|
* console.log(this.control.value); // 'Nancy'
|
410
|
* ```
|
411
|
*
|
412
|
* OR
|
413
|
*
|
414
|
* ```
|
415
|
* this.control.reset({value: 'Nancy', disabled: true});
|
416
|
*
|
417
|
* console.log(this.control.value); // 'Nancy'
|
418
|
* console.log(this.control.status); // 'DISABLED'
|
419
|
* ```
|
420
|
*/
|
421
|
reset(formState?: any, options?: {
|
422
|
onlySelf?: boolean;
|
423
|
emitEvent?: boolean;
|
424
|
}): void;
|
425
|
/**
|
426
|
* Register a listener for change events.
|
427
|
*/
|
428
|
registerOnChange(fn: Function): void;
|
429
|
/**
|
430
|
* Register a listener for disabled events.
|
431
|
*/
|
432
|
registerOnDisabledChange(fn: (isDisabled: boolean) => void): void;
|
433
|
private _applyFormState(formState);
|
434
|
}
|
435
|
/**
|
436
|
* @whatItDoes Tracks the value and validity state of a group of {@link FormControl}
|
437
|
* instances.
|
438
|
*
|
439
|
* A `FormGroup` aggregates the values of each child {@link FormControl} into one object,
|
440
|
* with each control name as the key. It calculates its status by reducing the statuses
|
441
|
* of its children. For example, if one of the controls in a group is invalid, the entire
|
442
|
* group becomes invalid.
|
443
|
*
|
444
|
* `FormGroup` is one of the three fundamental building blocks used to define forms in Angular,
|
445
|
* along with {@link FormControl} and {@link FormArray}.
|
446
|
*
|
447
|
* @howToUse
|
448
|
*
|
449
|
* When instantiating a {@link FormGroup}, pass in a collection of child controls as the first
|
450
|
* argument. The key for each child will be the name under which it is registered.
|
451
|
*
|
452
|
* ### Example
|
453
|
*
|
454
|
* ```
|
455
|
* const form = new FormGroup({
|
456
|
* first: new FormControl('Nancy', Validators.minLength(2)),
|
457
|
* last: new FormControl('Drew'),
|
458
|
* });
|
459
|
*
|
460
|
* console.log(form.value); // {first: 'Nancy', last; 'Drew'}
|
461
|
* console.log(form.status); // 'VALID'
|
462
|
* ```
|
463
|
*
|
464
|
* You can also include group-level validators as the second arg, or group-level async
|
465
|
* validators as the third arg. These come in handy when you want to perform validation
|
466
|
* that considers the value of more than one child control.
|
467
|
*
|
468
|
* ### Example
|
469
|
*
|
470
|
* ```
|
471
|
* const form = new FormGroup({
|
472
|
* password: new FormControl('', Validators.minLength(2)),
|
473
|
* passwordConfirm: new FormControl('', Validators.minLength(2)),
|
474
|
* }, passwordMatchValidator);
|
475
|
*
|
476
|
*
|
477
|
* function passwordMatchValidator(g: FormGroup) {
|
478
|
* return g.get('password').value === g.get('passwordConfirm').value
|
479
|
* ? null : {'mismatch': true};
|
480
|
* }
|
481
|
* ```
|
482
|
*
|
483
|
* * **npm package**: `@angular/forms`
|
484
|
*
|
485
|
* @stable
|
486
|
*/
|
487
|
export declare class FormGroup extends AbstractControl {
|
488
|
controls: {
|
489
|
[key: string]: AbstractControl;
|
490
|
};
|
491
|
constructor(controls: {
|
492
|
[key: string]: AbstractControl;
|
493
|
}, validator?: ValidatorFn | null, asyncValidator?: AsyncValidatorFn | null);
|
494
|
/**
|
495
|
* Registers a control with the group's list of controls.
|
496
|
*
|
497
|
* This method does not update value or validity of the control, so for
|
498
|
* most cases you'll want to use {@link FormGroup#addControl} instead.
|
499
|
*/
|
500
|
registerControl(name: string, control: AbstractControl): AbstractControl;
|
501
|
/**
|
502
|
* Add a control to this group.
|
503
|
*/
|
504
|
addControl(name: string, control: AbstractControl): void;
|
505
|
/**
|
506
|
* Remove a control from this group.
|
507
|
*/
|
508
|
removeControl(name: string): void;
|
509
|
/**
|
510
|
* Replace an existing control.
|
511
|
*/
|
512
|
setControl(name: string, control: AbstractControl): void;
|
513
|
/**
|
514
|
* Check whether there is an enabled control with the given name in the group.
|
515
|
*
|
516
|
* It will return false for disabled controls. If you'd like to check for
|
517
|
* existence in the group only, use {@link AbstractControl#get} instead.
|
518
|
*/
|
519
|
contains(controlName: string): boolean;
|
520
|
/**
|
521
|
* Sets the value of the {@link FormGroup}. It accepts an object that matches
|
522
|
* the structure of the group, with control names as keys.
|
523
|
*
|
524
|
* This method performs strict checks, so it will throw an error if you try
|
525
|
* to set the value of a control that doesn't exist or if you exclude the
|
526
|
* value of a control.
|
527
|
*
|
528
|
* ### Example
|
529
|
*
|
530
|
* ```
|
531
|
* const form = new FormGroup({
|
532
|
* first: new FormControl(),
|
533
|
* last: new FormControl()
|
534
|
* });
|
535
|
* console.log(form.value); // {first: null, last: null}
|
536
|
*
|
537
|
* form.setValue({first: 'Nancy', last: 'Drew'});
|
538
|
* console.log(form.value); // {first: 'Nancy', last: 'Drew'}
|
539
|
*
|
540
|
* ```
|
541
|
*/
|
542
|
setValue(value: {
|
543
|
[key: string]: any;
|
544
|
}, options?: {
|
545
|
onlySelf?: boolean;
|
546
|
emitEvent?: boolean;
|
547
|
}): void;
|
548
|
/**
|
549
|
* Patches the value of the {@link FormGroup}. It accepts an object with control
|
550
|
* names as keys, and will do its best to match the values to the correct controls
|
551
|
* in the group.
|
552
|
*
|
553
|
* It accepts both super-sets and sub-sets of the group without throwing an error.
|
554
|
*
|
555
|
* ### Example
|
556
|
*
|
557
|
* ```
|
558
|
* const form = new FormGroup({
|
559
|
* first: new FormControl(),
|
560
|
* last: new FormControl()
|
561
|
* });
|
562
|
* console.log(form.value); // {first: null, last: null}
|
563
|
*
|
564
|
* form.patchValue({first: 'Nancy'});
|
565
|
* console.log(form.value); // {first: 'Nancy', last: null}
|
566
|
*
|
567
|
* ```
|
568
|
*/
|
569
|
patchValue(value: {
|
570
|
[key: string]: any;
|
571
|
}, options?: {
|
572
|
onlySelf?: boolean;
|
573
|
emitEvent?: boolean;
|
574
|
}): void;
|
575
|
/**
|
576
|
* Resets the {@link FormGroup}. This means by default:
|
577
|
*
|
578
|
* * The group and all descendants are marked `pristine`
|
579
|
* * The group and all descendants are marked `untouched`
|
580
|
* * The value of all descendants will be null or null maps
|
581
|
*
|
582
|
* You can also reset to a specific form state by passing in a map of states
|
583
|
* that matches the structure of your form, with control names as keys. The state
|
584
|
* can be a standalone value or a form state object with both a value and a disabled
|
585
|
* status.
|
586
|
*
|
587
|
* ### Example
|
588
|
*
|
589
|
* ```ts
|
590
|
* this.form.reset({first: 'name', last: 'last name'});
|
591
|
*
|
592
|
* console.log(this.form.value); // {first: 'name', last: 'last name'}
|
593
|
* ```
|
594
|
*
|
595
|
* - OR -
|
596
|
*
|
597
|
* ```
|
598
|
* this.form.reset({
|
599
|
* first: {value: 'name', disabled: true},
|
600
|
* last: 'last'
|
601
|
* });
|
602
|
*
|
603
|
* console.log(this.form.value); // {first: 'name', last: 'last name'}
|
604
|
* console.log(this.form.get('first').status); // 'DISABLED'
|
605
|
* ```
|
606
|
*/
|
607
|
reset(value?: any, options?: {
|
608
|
onlySelf?: boolean;
|
609
|
emitEvent?: boolean;
|
610
|
}): void;
|
611
|
/**
|
612
|
* The aggregate value of the {@link FormGroup}, including any disabled controls.
|
613
|
*
|
614
|
* If you'd like to include all values regardless of disabled status, use this method.
|
615
|
* Otherwise, the `value` property is the best way to get the value of the group.
|
616
|
*/
|
617
|
getRawValue(): any;
|
618
|
}
|
619
|
/**
|
620
|
* @whatItDoes Tracks the value and validity state of an array of {@link FormControl},
|
621
|
* {@link FormGroup} or {@link FormArray} instances.
|
622
|
*
|
623
|
* A `FormArray` aggregates the values of each child {@link FormControl} into an array.
|
624
|
* It calculates its status by reducing the statuses of its children. For example, if one of
|
625
|
* the controls in a `FormArray` is invalid, the entire array becomes invalid.
|
626
|
*
|
627
|
* `FormArray` is one of the three fundamental building blocks used to define forms in Angular,
|
628
|
* along with {@link FormControl} and {@link FormGroup}.
|
629
|
*
|
630
|
* @howToUse
|
631
|
*
|
632
|
* When instantiating a {@link FormArray}, pass in an array of child controls as the first
|
633
|
* argument.
|
634
|
*
|
635
|
* ### Example
|
636
|
*
|
637
|
* ```
|
638
|
* const arr = new FormArray([
|
639
|
* new FormControl('Nancy', Validators.minLength(2)),
|
640
|
* new FormControl('Drew'),
|
641
|
* ]);
|
642
|
*
|
643
|
* console.log(arr.value); // ['Nancy', 'Drew']
|
644
|
* console.log(arr.status); // 'VALID'
|
645
|
* ```
|
646
|
*
|
647
|
* You can also include array-level validators as the second arg, or array-level async
|
648
|
* validators as the third arg. These come in handy when you want to perform validation
|
649
|
* that considers the value of more than one child control.
|
650
|
*
|
651
|
* ### Adding or removing controls
|
652
|
*
|
653
|
* To change the controls in the array, use the `push`, `insert`, or `removeAt` methods
|
654
|
* in `FormArray` itself. These methods ensure the controls are properly tracked in the
|
655
|
* form's hierarchy. Do not modify the array of `AbstractControl`s used to instantiate
|
656
|
* the `FormArray` directly, as that will result in strange and unexpected behavior such
|
657
|
* as broken change detection.
|
658
|
*
|
659
|
* * **npm package**: `@angular/forms`
|
660
|
*
|
661
|
* @stable
|
662
|
*/
|
663
|
export declare class FormArray extends AbstractControl {
|
664
|
controls: AbstractControl[];
|
665
|
constructor(controls: AbstractControl[], validator?: ValidatorFn | null, asyncValidator?: AsyncValidatorFn | null);
|
666
|
/**
|
667
|
* Get the {@link AbstractControl} at the given `index` in the array.
|
668
|
*/
|
669
|
at(index: number): AbstractControl;
|
670
|
/**
|
671
|
* Insert a new {@link AbstractControl} at the end of the array.
|
672
|
*/
|
673
|
push(control: AbstractControl): void;
|
674
|
/**
|
675
|
* Insert a new {@link AbstractControl} at the given `index` in the array.
|
676
|
*/
|
677
|
insert(index: number, control: AbstractControl): void;
|
678
|
/**
|
679
|
* Remove the control at the given `index` in the array.
|
680
|
*/
|
681
|
removeAt(index: number): void;
|
682
|
/**
|
683
|
* Replace an existing control.
|
684
|
*/
|
685
|
setControl(index: number, control: AbstractControl): void;
|
686
|
/**
|
687
|
* Length of the control array.
|
688
|
*/
|
689
|
readonly length: number;
|
690
|
/**
|
691
|
* Sets the value of the {@link FormArray}. It accepts an array that matches
|
692
|
* the structure of the control.
|
693
|
*
|
694
|
* This method performs strict checks, so it will throw an error if you try
|
695
|
* to set the value of a control that doesn't exist or if you exclude the
|
696
|
* value of a control.
|
697
|
*
|
698
|
* ### Example
|
699
|
*
|
700
|
* ```
|
701
|
* const arr = new FormArray([
|
702
|
* new FormControl(),
|
703
|
* new FormControl()
|
704
|
* ]);
|
705
|
* console.log(arr.value); // [null, null]
|
706
|
*
|
707
|
* arr.setValue(['Nancy', 'Drew']);
|
708
|
* console.log(arr.value); // ['Nancy', 'Drew']
|
709
|
* ```
|
710
|
*/
|
711
|
setValue(value: any[], options?: {
|
712
|
onlySelf?: boolean;
|
713
|
emitEvent?: boolean;
|
714
|
}): void;
|
715
|
/**
|
716
|
* Patches the value of the {@link FormArray}. It accepts an array that matches the
|
717
|
* structure of the control, and will do its best to match the values to the correct
|
718
|
* controls in the group.
|
719
|
*
|
720
|
* It accepts both super-sets and sub-sets of the array without throwing an error.
|
721
|
*
|
722
|
* ### Example
|
723
|
*
|
724
|
* ```
|
725
|
* const arr = new FormArray([
|
726
|
* new FormControl(),
|
727
|
* new FormControl()
|
728
|
* ]);
|
729
|
* console.log(arr.value); // [null, null]
|
730
|
*
|
731
|
* arr.patchValue(['Nancy']);
|
732
|
* console.log(arr.value); // ['Nancy', null]
|
733
|
* ```
|
734
|
*/
|
735
|
patchValue(value: any[], options?: {
|
736
|
onlySelf?: boolean;
|
737
|
emitEvent?: boolean;
|
738
|
}): void;
|
739
|
/**
|
740
|
* Resets the {@link FormArray}. This means by default:
|
741
|
*
|
742
|
* * The array and all descendants are marked `pristine`
|
743
|
* * The array and all descendants are marked `untouched`
|
744
|
* * The value of all descendants will be null or null maps
|
745
|
*
|
746
|
* You can also reset to a specific form state by passing in an array of states
|
747
|
* that matches the structure of the control. The state can be a standalone value
|
748
|
* or a form state object with both a value and a disabled status.
|
749
|
*
|
750
|
* ### Example
|
751
|
*
|
752
|
* ```ts
|
753
|
* this.arr.reset(['name', 'last name']);
|
754
|
*
|
755
|
* console.log(this.arr.value); // ['name', 'last name']
|
756
|
* ```
|
757
|
*
|
758
|
* - OR -
|
759
|
*
|
760
|
* ```
|
761
|
* this.arr.reset([
|
762
|
* {value: 'name', disabled: true},
|
763
|
* 'last'
|
764
|
* ]);
|
765
|
*
|
766
|
* console.log(this.arr.value); // ['name', 'last name']
|
767
|
* console.log(this.arr.get(0).status); // 'DISABLED'
|
768
|
* ```
|
769
|
*/
|
770
|
reset(value?: any, options?: {
|
771
|
onlySelf?: boolean;
|
772
|
emitEvent?: boolean;
|
773
|
}): void;
|
774
|
/**
|
775
|
* The aggregate value of the array, including any disabled controls.
|
776
|
*
|
777
|
* If you'd like to include all values regardless of disabled status, use this method.
|
778
|
* Otherwise, the `value` property is the best way to get the value of the array.
|
779
|
*/
|
780
|
getRawValue(): any[];
|
781
|
private _registerControl(control);
|
782
|
}
|