@angular/forms 20.0.0 → 20.1.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/fesm2022/forms.mjs +140 -140
- package/fesm2022/forms.mjs.map +1 -1
- package/index.d.ts +767 -760
- package/package.json +4 -4
package/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Angular v20.0.0
|
|
2
|
+
* @license Angular v20.1.0-next.0
|
|
3
3
|
* (c) 2010-2025 Google LLC. https://angular.io/
|
|
4
4
|
* License: MIT
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import * as i0 from '@angular/core';
|
|
8
|
-
import { Renderer2, ElementRef,
|
|
8
|
+
import { InjectionToken, Renderer2, ElementRef, OnDestroy, OnChanges, SimpleChanges, OnInit, Injector, EventEmitter, ChangeDetectorRef, AfterViewInit, Version, ModuleWithProviders } from '@angular/core';
|
|
9
9
|
import { Observable } from 'rxjs';
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -255,9 +255,9 @@ declare const NG_VALUE_ACCESSOR: InjectionToken<readonly ControlValueAccessor[]>
|
|
|
255
255
|
*
|
|
256
256
|
* ```html
|
|
257
257
|
* <select [compareWith]="compareFn" [formControl]="selectedCountriesControl">
|
|
258
|
-
*
|
|
259
|
-
*
|
|
260
|
-
*
|
|
258
|
+
* @for(country of countries; track $index) {
|
|
259
|
+
* <option[ngValue]="country">{{country.name}}</option>
|
|
260
|
+
* }
|
|
261
261
|
* </select>
|
|
262
262
|
*
|
|
263
263
|
* compareFn(c1: Country, c2: Country): boolean {
|
|
@@ -354,9 +354,9 @@ declare class NgSelectOption implements OnDestroy {
|
|
|
354
354
|
*
|
|
355
355
|
* ```html
|
|
356
356
|
* <select multiple name="countries" [formControl]="countryControl">
|
|
357
|
-
*
|
|
358
|
-
*
|
|
359
|
-
*
|
|
357
|
+
* @for(country of countries; track $index) {
|
|
358
|
+
* <option [ngValue]="country">{{ country.name }}</option>
|
|
359
|
+
* }
|
|
360
360
|
* </select>
|
|
361
361
|
* ```
|
|
362
362
|
*
|
|
@@ -1346,283 +1346,240 @@ declare const UntypedFormArray: UntypedFormArrayCtor;
|
|
|
1346
1346
|
declare const isFormArray: (control: unknown) => control is FormArray;
|
|
1347
1347
|
|
|
1348
1348
|
/**
|
|
1349
|
-
*
|
|
1350
|
-
* case falls back to {[key: string]: any}.
|
|
1351
|
-
*
|
|
1352
|
-
* Angular uses this type internally to support Typed Forms; do not use it directly.
|
|
1349
|
+
* FormControlState is a boxed form value. It is an object with a `value` key and a `disabled` key.
|
|
1353
1350
|
*
|
|
1354
|
-
*
|
|
1351
|
+
* @publicApi
|
|
1355
1352
|
*/
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
}>, {
|
|
1361
|
-
[key: string]: any;
|
|
1362
|
-
}>;
|
|
1353
|
+
interface FormControlState<T> {
|
|
1354
|
+
value: T;
|
|
1355
|
+
disabled: boolean;
|
|
1356
|
+
}
|
|
1363
1357
|
/**
|
|
1364
|
-
*
|
|
1365
|
-
* untyped case falls back to {[key: string]: any}.
|
|
1358
|
+
* Interface for options provided to a `FormControl`.
|
|
1366
1359
|
*
|
|
1367
|
-
*
|
|
1360
|
+
* This interface extends all options from {@link AbstractControlOptions}, plus some options
|
|
1361
|
+
* unique to `FormControl`.
|
|
1368
1362
|
*
|
|
1369
|
-
*
|
|
1363
|
+
* @publicApi
|
|
1370
1364
|
*/
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1365
|
+
interface FormControlOptions extends AbstractControlOptions {
|
|
1366
|
+
/**
|
|
1367
|
+
* @description
|
|
1368
|
+
* Whether to use the initial value used to construct the `FormControl` as its default value
|
|
1369
|
+
* as well. If this option is false or not provided, the default value of a FormControl is `null`.
|
|
1370
|
+
* When a FormControl is reset without an explicit value, its value reverts to
|
|
1371
|
+
* its default value.
|
|
1372
|
+
*/
|
|
1373
|
+
nonNullable?: boolean;
|
|
1374
|
+
/**
|
|
1375
|
+
* @deprecated Use `nonNullable` instead.
|
|
1376
|
+
*/
|
|
1377
|
+
initialValueIsDefault?: boolean;
|
|
1378
|
+
}
|
|
1378
1379
|
/**
|
|
1379
|
-
*
|
|
1380
|
-
*
|
|
1381
|
-
*
|
|
1380
|
+
* Various available constructors for `FormControl`.
|
|
1381
|
+
* Do not use this interface directly. Instead, use `FormControl`:
|
|
1382
|
+
* ```ts
|
|
1383
|
+
* const fc = new FormControl('foo');
|
|
1384
|
+
* ```
|
|
1385
|
+
* This symbol is prefixed with ɵ to make plain that it is an internal symbol.
|
|
1382
1386
|
*/
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1387
|
+
interface ɵFormControlCtor {
|
|
1388
|
+
/**
|
|
1389
|
+
* Construct a FormControl with no initial value or validators.
|
|
1390
|
+
*/
|
|
1391
|
+
new (): FormControl<any>;
|
|
1392
|
+
/**
|
|
1393
|
+
* Creates a new `FormControl` instance.
|
|
1394
|
+
*
|
|
1395
|
+
* @param value Initializes the control with an initial value,
|
|
1396
|
+
* or an object that defines the initial value and disabled state.
|
|
1397
|
+
*
|
|
1398
|
+
* @param opts A `FormControlOptions` object that contains validation functions and a
|
|
1399
|
+
* validation trigger. `nonNullable` have to be `true`
|
|
1400
|
+
*/
|
|
1401
|
+
new <T = any>(value: FormControlState<T> | T, opts: FormControlOptions & {
|
|
1402
|
+
nonNullable: true;
|
|
1403
|
+
}): FormControl<T>;
|
|
1404
|
+
/**
|
|
1405
|
+
* @deprecated Use `nonNullable` instead.
|
|
1406
|
+
*/
|
|
1407
|
+
new <T = any>(value: FormControlState<T> | T, opts: FormControlOptions & {
|
|
1408
|
+
initialValueIsDefault: true;
|
|
1409
|
+
}): FormControl<T>;
|
|
1410
|
+
/**
|
|
1411
|
+
* @deprecated When passing an `options` argument, the `asyncValidator` argument has no effect.
|
|
1412
|
+
*/
|
|
1413
|
+
new <T = any>(value: FormControlState<T> | T, opts: FormControlOptions, asyncValidator: AsyncValidatorFn | AsyncValidatorFn[]): FormControl<T | null>;
|
|
1414
|
+
/**
|
|
1415
|
+
* Creates a new `FormControl` instance.
|
|
1416
|
+
*
|
|
1417
|
+
* @param value Initializes the control with an initial value,
|
|
1418
|
+
* or an object that defines the initial value and disabled state.
|
|
1419
|
+
*
|
|
1420
|
+
* @param validatorOrOpts A synchronous validator function, or an array of
|
|
1421
|
+
* such functions, or a `FormControlOptions` object that contains validation functions
|
|
1422
|
+
* and a validation trigger.
|
|
1423
|
+
*
|
|
1424
|
+
* @param asyncValidator A single async validator or array of async validator functions
|
|
1425
|
+
*/
|
|
1426
|
+
new <T = any>(value: FormControlState<T> | T, validatorOrOpts?: ValidatorFn | ValidatorFn[] | FormControlOptions | null, asyncValidator?: AsyncValidatorFn | AsyncValidatorFn[] | null): FormControl<T | null>;
|
|
1427
|
+
/**
|
|
1428
|
+
* The presence of an explicit `prototype` property provides backwards-compatibility for apps that
|
|
1429
|
+
* manually inspect the prototype chain.
|
|
1430
|
+
*/
|
|
1431
|
+
prototype: FormControl<any>;
|
|
1432
|
+
}
|
|
1386
1433
|
/**
|
|
1387
|
-
* Tracks the value and
|
|
1434
|
+
* Tracks the value and validation status of an individual form control.
|
|
1388
1435
|
*
|
|
1389
|
-
*
|
|
1390
|
-
*
|
|
1391
|
-
*
|
|
1392
|
-
*
|
|
1436
|
+
* This is one of the four fundamental building blocks of Angular forms, along with
|
|
1437
|
+
* `FormGroup`, `FormArray` and `FormRecord`. It extends the `AbstractControl` class that
|
|
1438
|
+
* implements most of the base functionality for accessing the value, validation status,
|
|
1439
|
+
* user interactions and events.
|
|
1393
1440
|
*
|
|
1394
|
-
* `
|
|
1395
|
-
*
|
|
1441
|
+
* `FormControl` takes a single generic argument, which describes the type of its value. This
|
|
1442
|
+
* argument always implicitly includes `null` because the control can be reset. To change this
|
|
1443
|
+
* behavior, set `nonNullable` or see the usage notes below.
|
|
1396
1444
|
*
|
|
1397
|
-
*
|
|
1398
|
-
* argument. The key for each child registers the name for the control.
|
|
1445
|
+
* See [usage examples below](#usage-notes).
|
|
1399
1446
|
*
|
|
1400
|
-
*
|
|
1401
|
-
*
|
|
1447
|
+
* @see {@link AbstractControl}
|
|
1448
|
+
* @see [Reactive Forms Guide](guide/forms/reactive-forms)
|
|
1449
|
+
* @see [Usage Notes](#usage-notes)
|
|
1402
1450
|
*
|
|
1403
|
-
*
|
|
1404
|
-
*
|
|
1451
|
+
* @publicApi
|
|
1452
|
+
*
|
|
1453
|
+
* @overriddenImplementation ɵFormControlCtor
|
|
1405
1454
|
*
|
|
1406
1455
|
* @usageNotes
|
|
1407
1456
|
*
|
|
1408
|
-
* ###
|
|
1457
|
+
* ### Initializing Form Controls
|
|
1458
|
+
*
|
|
1459
|
+
* Instantiate a `FormControl`, with an initial value.
|
|
1409
1460
|
*
|
|
1410
1461
|
* ```ts
|
|
1411
|
-
* const
|
|
1412
|
-
*
|
|
1413
|
-
*
|
|
1414
|
-
* });
|
|
1462
|
+
* const control = new FormControl('some value');
|
|
1463
|
+
* console.log(control.value); // 'some value'
|
|
1464
|
+
* ```
|
|
1415
1465
|
*
|
|
1416
|
-
*
|
|
1417
|
-
*
|
|
1466
|
+
* The following example initializes the control with a form state object. The `value`
|
|
1467
|
+
* and `disabled` keys are required in this case.
|
|
1468
|
+
*
|
|
1469
|
+
* ```ts
|
|
1470
|
+
* const control = new FormControl({ value: 'n/a', disabled: true });
|
|
1471
|
+
* console.log(control.value); // 'n/a'
|
|
1472
|
+
* console.log(control.status); // 'DISABLED'
|
|
1418
1473
|
* ```
|
|
1419
1474
|
*
|
|
1420
|
-
*
|
|
1475
|
+
* The following example initializes the control with a synchronous validator.
|
|
1421
1476
|
*
|
|
1422
|
-
*
|
|
1423
|
-
*
|
|
1424
|
-
*
|
|
1477
|
+
* ```ts
|
|
1478
|
+
* const control = new FormControl('', Validators.required);
|
|
1479
|
+
* console.log(control.value); // ''
|
|
1480
|
+
* console.log(control.status); // 'INVALID'
|
|
1481
|
+
* ```
|
|
1425
1482
|
*
|
|
1426
|
-
*
|
|
1427
|
-
* type):
|
|
1483
|
+
* The following example initializes the control using an options object.
|
|
1428
1484
|
*
|
|
1429
1485
|
* ```ts
|
|
1430
|
-
* const
|
|
1431
|
-
*
|
|
1432
|
-
*
|
|
1433
|
-
* last: FormControl<string|null>,
|
|
1434
|
-
* }>({
|
|
1435
|
-
* first: new FormControl('Nancy'),
|
|
1436
|
-
* last: new FormControl('Drew'),
|
|
1486
|
+
* const control = new FormControl('', {
|
|
1487
|
+
* validators: Validators.required,
|
|
1488
|
+
* asyncValidators: myAsyncValidator
|
|
1437
1489
|
* });
|
|
1438
1490
|
* ```
|
|
1439
1491
|
*
|
|
1440
|
-
* ###
|
|
1492
|
+
* ### The single type argument
|
|
1441
1493
|
*
|
|
1442
|
-
*
|
|
1443
|
-
*
|
|
1444
|
-
*
|
|
1494
|
+
* `FormControl` accepts a generic argument, which describes the type of its value.
|
|
1495
|
+
* In most cases, this argument will be inferred.
|
|
1496
|
+
*
|
|
1497
|
+
* If you are initializing the control to `null`, or you otherwise wish to provide a
|
|
1498
|
+
* wider type, you may specify the argument explicitly:
|
|
1445
1499
|
*
|
|
1446
1500
|
* ```ts
|
|
1447
|
-
*
|
|
1448
|
-
*
|
|
1449
|
-
*
|
|
1450
|
-
* }, passwordMatchValidator);
|
|
1501
|
+
* let fc = new FormControl<string|null>(null);
|
|
1502
|
+
* fc.setValue('foo');
|
|
1503
|
+
* ```
|
|
1451
1504
|
*
|
|
1505
|
+
* You might notice that `null` is always added to the type of the control.
|
|
1506
|
+
* This is because the control will become `null` if you call `reset`. You can change
|
|
1507
|
+
* this behavior by setting `{nonNullable: true}`.
|
|
1452
1508
|
*
|
|
1453
|
-
*
|
|
1454
|
-
*
|
|
1455
|
-
*
|
|
1456
|
-
*
|
|
1509
|
+
* ### Configure the control to update on a blur event
|
|
1510
|
+
*
|
|
1511
|
+
* Set the `updateOn` option to `'blur'` to update on the blur `event`.
|
|
1512
|
+
*
|
|
1513
|
+
* ```ts
|
|
1514
|
+
* const control = new FormControl('', { updateOn: 'blur' });
|
|
1457
1515
|
* ```
|
|
1458
1516
|
*
|
|
1459
|
-
*
|
|
1460
|
-
*
|
|
1517
|
+
* ### Configure the control to update on a submit event
|
|
1518
|
+
*
|
|
1519
|
+
* Set the `updateOn` option to `'submit'` to update on a submit `event`.
|
|
1461
1520
|
*
|
|
1462
1521
|
* ```ts
|
|
1463
|
-
* const
|
|
1464
|
-
* password: new FormControl('')
|
|
1465
|
-
* passwordConfirm: new FormControl('')
|
|
1466
|
-
* }, { validators: passwordMatchValidator, asyncValidators: otherValidator });
|
|
1522
|
+
* const control = new FormControl('', { updateOn: 'submit' });
|
|
1467
1523
|
* ```
|
|
1468
1524
|
*
|
|
1469
|
-
* ###
|
|
1525
|
+
* ### Reset the control back to a specific value
|
|
1470
1526
|
*
|
|
1471
|
-
*
|
|
1472
|
-
*
|
|
1473
|
-
*
|
|
1474
|
-
* has explicitly specified a different `updateOn` value.
|
|
1527
|
+
* You reset to a specific form state by passing through a standalone
|
|
1528
|
+
* value or a form state object that contains both a value and a disabled state
|
|
1529
|
+
* (these are the only two properties that cannot be calculated).
|
|
1475
1530
|
*
|
|
1476
1531
|
* ```ts
|
|
1477
|
-
* const
|
|
1478
|
-
*
|
|
1479
|
-
*
|
|
1532
|
+
* const control = new FormControl('Nancy');
|
|
1533
|
+
*
|
|
1534
|
+
* console.log(control.value); // 'Nancy'
|
|
1535
|
+
*
|
|
1536
|
+
* control.reset('Drew');
|
|
1537
|
+
*
|
|
1538
|
+
* console.log(control.value); // 'Drew'
|
|
1480
1539
|
* ```
|
|
1481
1540
|
*
|
|
1482
|
-
* ###
|
|
1541
|
+
* ### Reset the control to its initial value
|
|
1483
1542
|
*
|
|
1484
|
-
*
|
|
1485
|
-
*
|
|
1486
|
-
* declared optional in the group's type.
|
|
1543
|
+
* If you wish to always reset the control to its initial value (instead of null),
|
|
1544
|
+
* you can pass the `nonNullable` option:
|
|
1487
1545
|
*
|
|
1488
1546
|
* ```ts
|
|
1489
|
-
* const
|
|
1490
|
-
*
|
|
1491
|
-
*
|
|
1547
|
+
* const control = new FormControl('Nancy', {nonNullable: true});
|
|
1548
|
+
*
|
|
1549
|
+
* console.log(control.value); // 'Nancy'
|
|
1550
|
+
*
|
|
1551
|
+
* control.reset();
|
|
1552
|
+
*
|
|
1553
|
+
* console.log(control.value); // 'Nancy'
|
|
1492
1554
|
* ```
|
|
1493
1555
|
*
|
|
1494
|
-
*
|
|
1495
|
-
* without providing the optional key `one` will cause it to become `null`.
|
|
1556
|
+
* ### Reset the control back to an initial value and disabled
|
|
1496
1557
|
*
|
|
1497
|
-
*
|
|
1558
|
+
* ```ts
|
|
1559
|
+
* const control = new FormControl('Nancy');
|
|
1560
|
+
*
|
|
1561
|
+
* console.log(control.value); // 'Nancy'
|
|
1562
|
+
* console.log(control.status); // 'VALID'
|
|
1563
|
+
*
|
|
1564
|
+
* control.reset({ value: 'Drew', disabled: true });
|
|
1565
|
+
*
|
|
1566
|
+
* console.log(control.value); // 'Drew'
|
|
1567
|
+
* console.log(control.status); // 'DISABLED'
|
|
1568
|
+
* ```
|
|
1498
1569
|
*/
|
|
1499
|
-
|
|
1500
|
-
[K in keyof TControl]: AbstractControl<any>;
|
|
1501
|
-
} = any> extends AbstractControl<ɵTypedOrUntyped<TControl, ɵFormGroupValue<TControl>, any>, ɵTypedOrUntyped<TControl, ɵFormGroupRawValue<TControl>, any>> {
|
|
1502
|
-
/**
|
|
1503
|
-
* Creates a new `FormGroup` instance.
|
|
1504
|
-
*
|
|
1505
|
-
* @param controls A collection of child controls. The key for each child is the name
|
|
1506
|
-
* under which it is registered.
|
|
1507
|
-
*
|
|
1508
|
-
* @param validatorOrOpts A synchronous validator function, or an array of
|
|
1509
|
-
* such functions, or an `AbstractControlOptions` object that contains validation functions
|
|
1510
|
-
* and a validation trigger.
|
|
1511
|
-
*
|
|
1512
|
-
* @param asyncValidator A single async validator or array of async validator functions
|
|
1513
|
-
*
|
|
1514
|
-
*/
|
|
1515
|
-
constructor(controls: TControl, validatorOrOpts?: ValidatorFn | ValidatorFn[] | AbstractControlOptions | null, asyncValidator?: AsyncValidatorFn | AsyncValidatorFn[] | null);
|
|
1516
|
-
controls: ɵTypedOrUntyped<TControl, TControl, {
|
|
1517
|
-
[key: string]: AbstractControl<any>;
|
|
1518
|
-
}>;
|
|
1519
|
-
/**
|
|
1520
|
-
* Registers a control with the group's list of controls. In a strongly-typed group, the control
|
|
1521
|
-
* must be in the group's type (possibly as an optional key).
|
|
1522
|
-
*
|
|
1523
|
-
* This method does not update the value or validity of the control.
|
|
1524
|
-
* Use {@link FormGroup#addControl addControl} instead.
|
|
1525
|
-
*
|
|
1526
|
-
* @param name The control name to register in the collection
|
|
1527
|
-
* @param control Provides the control for the given name
|
|
1528
|
-
*/
|
|
1529
|
-
registerControl<K extends string & keyof TControl>(name: K, control: TControl[K]): TControl[K];
|
|
1530
|
-
registerControl(this: FormGroup<{
|
|
1531
|
-
[key: string]: AbstractControl<any>;
|
|
1532
|
-
}>, name: string, control: AbstractControl<any>): AbstractControl<any>;
|
|
1533
|
-
/**
|
|
1534
|
-
* Add a control to this group. In a strongly-typed group, the control must be in the group's type
|
|
1535
|
-
* (possibly as an optional key).
|
|
1536
|
-
*
|
|
1537
|
-
* If a control with a given name already exists, it would *not* be replaced with a new one.
|
|
1538
|
-
* If you want to replace an existing control, use the {@link FormGroup#setControl setControl}
|
|
1539
|
-
* method instead. This method also updates the value and validity of the control.
|
|
1540
|
-
*
|
|
1541
|
-
* @param name The control name to add to the collection
|
|
1542
|
-
* @param control Provides the control for the given name
|
|
1543
|
-
* @param options Specifies whether this FormGroup instance should emit events after a new
|
|
1544
|
-
* control is added.
|
|
1545
|
-
* * `emitEvent`: When true or not supplied (the default), both the `statusChanges` and
|
|
1546
|
-
* `valueChanges` observables emit events with the latest status and value when the control is
|
|
1547
|
-
* added. When false, no events are emitted.
|
|
1548
|
-
*/
|
|
1549
|
-
addControl(this: FormGroup<{
|
|
1550
|
-
[key: string]: AbstractControl<any>;
|
|
1551
|
-
}>, name: string, control: AbstractControl, options?: {
|
|
1552
|
-
emitEvent?: boolean;
|
|
1553
|
-
}): void;
|
|
1554
|
-
addControl<K extends string & keyof TControl>(name: K, control: Required<TControl>[K], options?: {
|
|
1555
|
-
emitEvent?: boolean;
|
|
1556
|
-
}): void;
|
|
1557
|
-
removeControl(this: FormGroup<{
|
|
1558
|
-
[key: string]: AbstractControl<any>;
|
|
1559
|
-
}>, name: string, options?: {
|
|
1560
|
-
emitEvent?: boolean;
|
|
1561
|
-
}): void;
|
|
1562
|
-
removeControl<S extends string>(name: ɵOptionalKeys<TControl> & S, options?: {
|
|
1563
|
-
emitEvent?: boolean;
|
|
1564
|
-
}): void;
|
|
1565
|
-
/**
|
|
1566
|
-
* Replace an existing control. In a strongly-typed group, the control must be in the group's type
|
|
1567
|
-
* (possibly as an optional key).
|
|
1568
|
-
*
|
|
1569
|
-
* If a control with a given name does not exist in this `FormGroup`, it will be added.
|
|
1570
|
-
*
|
|
1571
|
-
* @param name The control name to replace in the collection
|
|
1572
|
-
* @param control Provides the control for the given name
|
|
1573
|
-
* @param options Specifies whether this FormGroup instance should emit events after an
|
|
1574
|
-
* existing control is replaced.
|
|
1575
|
-
* * `emitEvent`: When true or not supplied (the default), both the `statusChanges` and
|
|
1576
|
-
* `valueChanges` observables emit events with the latest status and value when the control is
|
|
1577
|
-
* replaced with a new one. When false, no events are emitted.
|
|
1578
|
-
*/
|
|
1579
|
-
setControl<K extends string & keyof TControl>(name: K, control: TControl[K], options?: {
|
|
1580
|
-
emitEvent?: boolean;
|
|
1581
|
-
}): void;
|
|
1582
|
-
setControl(this: FormGroup<{
|
|
1583
|
-
[key: string]: AbstractControl<any>;
|
|
1584
|
-
}>, name: string, control: AbstractControl, options?: {
|
|
1585
|
-
emitEvent?: boolean;
|
|
1586
|
-
}): void;
|
|
1570
|
+
interface FormControl<TValue = any> extends AbstractControl<TValue> {
|
|
1587
1571
|
/**
|
|
1588
|
-
*
|
|
1589
|
-
*
|
|
1590
|
-
*
|
|
1591
|
-
* only, use {@link AbstractControl#get get} instead.
|
|
1592
|
-
*
|
|
1593
|
-
* @param controlName The control name to check for existence in the collection
|
|
1594
|
-
*
|
|
1595
|
-
* @returns false for disabled controls, true otherwise.
|
|
1572
|
+
* The default value of this FormControl, used whenever the control is reset without an explicit
|
|
1573
|
+
* value. See {@link FormControlOptions#nonNullable} for more information on configuring
|
|
1574
|
+
* a default value.
|
|
1596
1575
|
*/
|
|
1597
|
-
|
|
1598
|
-
contains(this: FormGroup<{
|
|
1599
|
-
[key: string]: AbstractControl<any>;
|
|
1600
|
-
}>, controlName: string): boolean;
|
|
1576
|
+
readonly defaultValue: TValue;
|
|
1601
1577
|
/**
|
|
1602
|
-
* Sets
|
|
1603
|
-
* the structure of the group, with control names as keys.
|
|
1604
|
-
*
|
|
1605
|
-
* @usageNotes
|
|
1606
|
-
* ### Set the complete value for the form group
|
|
1607
|
-
*
|
|
1608
|
-
* ```ts
|
|
1609
|
-
* const form = new FormGroup({
|
|
1610
|
-
* first: new FormControl(),
|
|
1611
|
-
* last: new FormControl()
|
|
1612
|
-
* });
|
|
1613
|
-
*
|
|
1614
|
-
* console.log(form.value); // {first: null, last: null}
|
|
1615
|
-
*
|
|
1616
|
-
* form.setValue({first: 'Nancy', last: 'Drew'});
|
|
1617
|
-
* console.log(form.value); // {first: 'Nancy', last: 'Drew'}
|
|
1618
|
-
* ```
|
|
1619
|
-
*
|
|
1620
|
-
* @throws When strict checks fail, such as setting the value of a control
|
|
1621
|
-
* that doesn't exist or if you exclude a value of a control that does exist.
|
|
1578
|
+
* Sets a new value for the form control.
|
|
1622
1579
|
*
|
|
1623
|
-
* @param value The new value for the control
|
|
1580
|
+
* @param value The new value for the control.
|
|
1624
1581
|
* @param options Configuration options that determine how the control propagates changes
|
|
1625
|
-
* and emits events
|
|
1582
|
+
* and emits events when the value changes.
|
|
1626
1583
|
* The configuration options are passed to the {@link AbstractControl#updateValueAndValidity
|
|
1627
1584
|
* updateValueAndValidity} method.
|
|
1628
1585
|
*
|
|
@@ -1632,293 +1589,693 @@ declare class FormGroup<TControl extends {
|
|
|
1632
1589
|
* `valueChanges`
|
|
1633
1590
|
* observables emit events with the latest status and value when the control value is updated.
|
|
1634
1591
|
* When false, no events are emitted.
|
|
1592
|
+
* * `emitModelToViewChange`: When true or not supplied (the default), each change triggers an
|
|
1593
|
+
* `onChange` event to
|
|
1594
|
+
* update the view.
|
|
1595
|
+
* * `emitViewToModelChange`: When true or not supplied (the default), each change triggers an
|
|
1596
|
+
* `ngModelChange`
|
|
1597
|
+
* event to update the model.
|
|
1598
|
+
*
|
|
1635
1599
|
*/
|
|
1636
|
-
setValue(value:
|
|
1600
|
+
setValue(value: TValue, options?: {
|
|
1637
1601
|
onlySelf?: boolean;
|
|
1638
1602
|
emitEvent?: boolean;
|
|
1603
|
+
emitModelToViewChange?: boolean;
|
|
1604
|
+
emitViewToModelChange?: boolean;
|
|
1639
1605
|
}): void;
|
|
1640
1606
|
/**
|
|
1641
|
-
* Patches the value of
|
|
1642
|
-
* names as keys, and does its best to match the values to the correct controls
|
|
1643
|
-
* in the group.
|
|
1644
|
-
*
|
|
1645
|
-
* It accepts both super-sets and sub-sets of the group without throwing an error.
|
|
1646
|
-
*
|
|
1647
|
-
* @usageNotes
|
|
1648
|
-
* ### Patch the value for a form group
|
|
1649
|
-
*
|
|
1650
|
-
* ```ts
|
|
1651
|
-
* const form = new FormGroup({
|
|
1652
|
-
* first: new FormControl(),
|
|
1653
|
-
* last: new FormControl()
|
|
1654
|
-
* });
|
|
1655
|
-
* console.log(form.value); // {first: null, last: null}
|
|
1607
|
+
* Patches the value of a control.
|
|
1656
1608
|
*
|
|
1657
|
-
*
|
|
1658
|
-
*
|
|
1659
|
-
*
|
|
1609
|
+
* This function is functionally the same as {@link FormControl#setValue setValue} at this level.
|
|
1610
|
+
* It exists for symmetry with {@link FormGroup#patchValue patchValue} on `FormGroups` and
|
|
1611
|
+
* `FormArrays`, where it does behave differently.
|
|
1660
1612
|
*
|
|
1661
|
-
* @
|
|
1662
|
-
* @param options Configuration options that determine how the control propagates changes and
|
|
1663
|
-
* emits events after the value is patched.
|
|
1664
|
-
* * `onlySelf`: When true, each change only affects this control and not its parent. Default is
|
|
1665
|
-
* true.
|
|
1666
|
-
* * `emitEvent`: When true or not supplied (the default), both the `statusChanges` and
|
|
1667
|
-
* `valueChanges` observables emit events with the latest status and value when the control value
|
|
1668
|
-
* is updated. When false, no events are emitted. The configuration options are passed to
|
|
1669
|
-
* the {@link AbstractControl#updateValueAndValidity updateValueAndValidity} method.
|
|
1613
|
+
* @see {@link FormControl#setValue} for options
|
|
1670
1614
|
*/
|
|
1671
|
-
patchValue(value:
|
|
1615
|
+
patchValue(value: TValue, options?: {
|
|
1672
1616
|
onlySelf?: boolean;
|
|
1673
1617
|
emitEvent?: boolean;
|
|
1618
|
+
emitModelToViewChange?: boolean;
|
|
1619
|
+
emitViewToModelChange?: boolean;
|
|
1674
1620
|
}): void;
|
|
1675
1621
|
/**
|
|
1676
|
-
* Resets the
|
|
1677
|
-
* the value
|
|
1622
|
+
* Resets the form control, marking it `pristine` and `untouched`, and resetting
|
|
1623
|
+
* the value. The new value will be the provided value (if passed), `null`, or the initial value
|
|
1624
|
+
* if `nonNullable` was set in the constructor via {@link FormControlOptions}.
|
|
1678
1625
|
*
|
|
1679
|
-
*
|
|
1680
|
-
*
|
|
1681
|
-
*
|
|
1682
|
-
*
|
|
1626
|
+
* ```ts
|
|
1627
|
+
* // By default, the control will reset to null.
|
|
1628
|
+
* const dog = new FormControl('spot');
|
|
1629
|
+
* dog.reset(); // dog.value is null
|
|
1683
1630
|
*
|
|
1684
|
-
*
|
|
1631
|
+
* // If this flag is set, the control will instead reset to the initial value.
|
|
1632
|
+
* const cat = new FormControl('tabby', {nonNullable: true});
|
|
1633
|
+
* cat.reset(); // cat.value is "tabby"
|
|
1634
|
+
*
|
|
1635
|
+
* // A value passed to reset always takes precedence.
|
|
1636
|
+
* const fish = new FormControl('finn', {nonNullable: true});
|
|
1637
|
+
* fish.reset('bubble'); // fish.value is "bubble"
|
|
1638
|
+
* ```
|
|
1639
|
+
*
|
|
1640
|
+
* @param formState Resets the control with an initial value,
|
|
1685
1641
|
* or an object that defines the initial value and disabled state.
|
|
1686
1642
|
*
|
|
1687
1643
|
* @param options Configuration options that determine how the control propagates changes
|
|
1688
|
-
* and emits events
|
|
1644
|
+
* and emits events after the value changes.
|
|
1645
|
+
*
|
|
1689
1646
|
* * `onlySelf`: When true, each change only affects this control, and not its parent. Default is
|
|
1690
1647
|
* false.
|
|
1691
1648
|
* * `emitEvent`: When true or not supplied (the default), both the `statusChanges` and
|
|
1692
1649
|
* `valueChanges`
|
|
1693
1650
|
* observables emit events with the latest status and value when the control is reset.
|
|
1694
1651
|
* When false, no events are emitted.
|
|
1695
|
-
* The configuration options are passed to the {@link AbstractControl#updateValueAndValidity
|
|
1696
|
-
* updateValueAndValidity} method.
|
|
1697
|
-
*
|
|
1698
|
-
* @usageNotes
|
|
1699
|
-
*
|
|
1700
|
-
* ### Reset the form group values
|
|
1701
|
-
*
|
|
1702
|
-
* ```ts
|
|
1703
|
-
* const form = new FormGroup({
|
|
1704
|
-
* first: new FormControl('first name'),
|
|
1705
|
-
* last: new FormControl('last name')
|
|
1706
|
-
* });
|
|
1707
|
-
*
|
|
1708
|
-
* console.log(form.value); // {first: 'first name', last: 'last name'}
|
|
1709
|
-
*
|
|
1710
|
-
* form.reset({ first: 'name', last: 'last name' });
|
|
1711
|
-
*
|
|
1712
|
-
* console.log(form.value); // {first: 'name', last: 'last name'}
|
|
1713
|
-
* ```
|
|
1714
|
-
*
|
|
1715
|
-
* ### Reset the form group values and disabled status
|
|
1716
|
-
*
|
|
1717
|
-
* ```ts
|
|
1718
|
-
* const form = new FormGroup({
|
|
1719
|
-
* first: new FormControl('first name'),
|
|
1720
|
-
* last: new FormControl('last name')
|
|
1721
|
-
* });
|
|
1722
|
-
*
|
|
1723
|
-
* form.reset({
|
|
1724
|
-
* first: {value: 'name', disabled: true},
|
|
1725
|
-
* last: 'last'
|
|
1726
|
-
* });
|
|
1727
1652
|
*
|
|
1728
|
-
* console.log(form.value); // {last: 'last'}
|
|
1729
|
-
* console.log(form.get('first').status); // 'DISABLED'
|
|
1730
|
-
* ```
|
|
1731
1653
|
*/
|
|
1732
|
-
reset(
|
|
1654
|
+
reset(formState?: TValue | FormControlState<TValue>, options?: {
|
|
1733
1655
|
onlySelf?: boolean;
|
|
1734
1656
|
emitEvent?: boolean;
|
|
1735
1657
|
}): void;
|
|
1736
1658
|
/**
|
|
1737
|
-
*
|
|
1738
|
-
*
|
|
1739
|
-
* Retrieves all values regardless of disabled status.
|
|
1659
|
+
* For a simple FormControl, the raw value is equivalent to the value.
|
|
1740
1660
|
*/
|
|
1741
|
-
getRawValue():
|
|
1661
|
+
getRawValue(): TValue;
|
|
1662
|
+
/**
|
|
1663
|
+
* Register a listener for change events.
|
|
1664
|
+
*
|
|
1665
|
+
* @param fn The method that is called when the value changes
|
|
1666
|
+
*/
|
|
1667
|
+
registerOnChange(fn: Function): void;
|
|
1668
|
+
/**
|
|
1669
|
+
* Register a listener for disabled events.
|
|
1670
|
+
*
|
|
1671
|
+
* @param fn The method that is called when the disabled status changes.
|
|
1672
|
+
*/
|
|
1673
|
+
registerOnDisabledChange(fn: (isDisabled: boolean) => void): void;
|
|
1742
1674
|
}
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1675
|
+
declare const FormControl: ɵFormControlCtor;
|
|
1676
|
+
interface UntypedFormControlCtor {
|
|
1677
|
+
new (): UntypedFormControl;
|
|
1678
|
+
new (formState?: any, validatorOrOpts?: ValidatorFn | ValidatorFn[] | FormControlOptions | null, asyncValidator?: AsyncValidatorFn | AsyncValidatorFn[] | null): UntypedFormControl;
|
|
1747
1679
|
/**
|
|
1748
1680
|
* The presence of an explicit `prototype` property provides backwards-compatibility for apps that
|
|
1749
1681
|
* manually inspect the prototype chain.
|
|
1750
1682
|
*/
|
|
1751
|
-
prototype:
|
|
1683
|
+
prototype: FormControl<any>;
|
|
1752
1684
|
}
|
|
1753
1685
|
/**
|
|
1754
|
-
*
|
|
1686
|
+
* UntypedFormControl is a non-strongly-typed version of `FormControl`.
|
|
1755
1687
|
*/
|
|
1756
|
-
type
|
|
1757
|
-
declare const
|
|
1688
|
+
type UntypedFormControl = FormControl<any>;
|
|
1689
|
+
declare const UntypedFormControl: UntypedFormControlCtor;
|
|
1758
1690
|
/**
|
|
1759
1691
|
* @description
|
|
1760
|
-
* Asserts that the given control is an instance of `
|
|
1692
|
+
* Asserts that the given control is an instance of `FormControl`
|
|
1761
1693
|
*
|
|
1762
1694
|
* @publicApi
|
|
1763
1695
|
*/
|
|
1764
|
-
declare const
|
|
1696
|
+
declare const isFormControl: (control: unknown) => control is FormControl;
|
|
1697
|
+
|
|
1765
1698
|
/**
|
|
1766
|
-
*
|
|
1767
|
-
*
|
|
1699
|
+
* FormGroupValue extracts the type of `.value` from a FormGroup's inner object type. The untyped
|
|
1700
|
+
* case falls back to {[key: string]: any}.
|
|
1768
1701
|
*
|
|
1769
|
-
*
|
|
1770
|
-
* with controls added and removed as needed.
|
|
1702
|
+
* Angular uses this type internally to support Typed Forms; do not use it directly.
|
|
1771
1703
|
*
|
|
1772
|
-
*
|
|
1704
|
+
* For internal use only.
|
|
1705
|
+
*/
|
|
1706
|
+
type ɵFormGroupArgumentValue<T extends {
|
|
1707
|
+
[K in keyof T]?: AbstractControl<any>;
|
|
1708
|
+
}> = ɵTypedOrUntyped<T, Partial<{
|
|
1709
|
+
[K in keyof T]: ɵValue<T[K]> | FormControlState<ɵValue<T[K]>>;
|
|
1710
|
+
}>, {
|
|
1711
|
+
[key: string]: any;
|
|
1712
|
+
}>;
|
|
1713
|
+
type ɵFormGroupValue<T extends {
|
|
1714
|
+
[K in keyof T]?: AbstractControl<any>;
|
|
1715
|
+
}> = ɵTypedOrUntyped<T, Partial<{
|
|
1716
|
+
[K in keyof T]: ɵValue<T[K]>;
|
|
1717
|
+
}>, {
|
|
1718
|
+
[key: string]: any;
|
|
1719
|
+
}>;
|
|
1720
|
+
/**
|
|
1721
|
+
* FormGroupRawValue extracts the type of `.getRawValue()` from a FormGroup's inner object type. The
|
|
1722
|
+
* untyped case falls back to {[key: string]: any}.
|
|
1723
|
+
*
|
|
1724
|
+
* Angular uses this type internally to support Typed Forms; do not use it directly.
|
|
1725
|
+
*
|
|
1726
|
+
* For internal use only.
|
|
1727
|
+
*/
|
|
1728
|
+
type ɵFormGroupRawValue<T extends {
|
|
1729
|
+
[K in keyof T]?: AbstractControl<any>;
|
|
1730
|
+
}> = ɵTypedOrUntyped<T, {
|
|
1731
|
+
[K in keyof T]: ɵRawValue<T[K]>;
|
|
1732
|
+
}, {
|
|
1733
|
+
[key: string]: any;
|
|
1734
|
+
}>;
|
|
1735
|
+
/**
|
|
1736
|
+
* OptionalKeys returns the union of all optional keys in the object.
|
|
1737
|
+
*
|
|
1738
|
+
* Angular uses this type internally to support Typed Forms; do not use it directly.
|
|
1739
|
+
*/
|
|
1740
|
+
type ɵOptionalKeys<T> = {
|
|
1741
|
+
[K in keyof T]-?: undefined extends T[K] ? K : never;
|
|
1742
|
+
}[keyof T];
|
|
1743
|
+
/**
|
|
1744
|
+
* Tracks the value and validity state of a group of `FormControl` instances.
|
|
1745
|
+
*
|
|
1746
|
+
* A `FormGroup` aggregates the values of each child `FormControl` into one object,
|
|
1747
|
+
* with each control name as the key. It calculates its status by reducing the status values
|
|
1748
|
+
* of its children. For example, if one of the controls in a group is invalid, the entire
|
|
1749
|
+
* group becomes invalid.
|
|
1750
|
+
*
|
|
1751
|
+
* `FormGroup` is one of the four fundamental building blocks used to define forms in Angular,
|
|
1752
|
+
* along with `FormControl`, `FormArray`, and `FormRecord`.
|
|
1753
|
+
*
|
|
1754
|
+
* When instantiating a `FormGroup`, pass in a collection of child controls as the first
|
|
1755
|
+
* argument. The key for each child registers the name for the control.
|
|
1756
|
+
*
|
|
1757
|
+
* `FormGroup` is intended for use cases where the keys are known ahead of time.
|
|
1758
|
+
* If you need to dynamically add and remove controls, use {@link FormRecord} instead.
|
|
1759
|
+
*
|
|
1760
|
+
* `FormGroup` accepts an optional type parameter `TControl`, which is an object type with inner
|
|
1761
|
+
* control types as values.
|
|
1773
1762
|
*
|
|
1774
1763
|
* @usageNotes
|
|
1775
1764
|
*
|
|
1765
|
+
* ### Create a form group with 2 controls
|
|
1766
|
+
*
|
|
1776
1767
|
* ```ts
|
|
1777
|
-
*
|
|
1778
|
-
*
|
|
1779
|
-
*
|
|
1768
|
+
* const form = new FormGroup({
|
|
1769
|
+
* first: new FormControl('Nancy', Validators.minLength(2)),
|
|
1770
|
+
* last: new FormControl('Drew'),
|
|
1771
|
+
* });
|
|
1772
|
+
*
|
|
1773
|
+
* console.log(form.value); // {first: 'Nancy', last; 'Drew'}
|
|
1774
|
+
* console.log(form.status); // 'VALID'
|
|
1775
|
+
* ```
|
|
1776
|
+
*
|
|
1777
|
+
* ### The type argument, and optional controls
|
|
1778
|
+
*
|
|
1779
|
+
* `FormGroup` accepts one generic argument, which is an object containing its inner controls.
|
|
1780
|
+
* This type will usually be inferred automatically, but you can always specify it explicitly if you
|
|
1781
|
+
* wish.
|
|
1782
|
+
*
|
|
1783
|
+
* If you have controls that are optional (i.e. they can be removed, you can use the `?` in the
|
|
1784
|
+
* type):
|
|
1785
|
+
*
|
|
1786
|
+
* ```ts
|
|
1787
|
+
* const form = new FormGroup<{
|
|
1788
|
+
* first: FormControl<string|null>,
|
|
1789
|
+
* middle?: FormControl<string|null>, // Middle name is optional.
|
|
1790
|
+
* last: FormControl<string|null>,
|
|
1791
|
+
* }>({
|
|
1792
|
+
* first: new FormControl('Nancy'),
|
|
1793
|
+
* last: new FormControl('Drew'),
|
|
1794
|
+
* });
|
|
1795
|
+
* ```
|
|
1796
|
+
*
|
|
1797
|
+
* ### Create a form group with a group-level validator
|
|
1798
|
+
*
|
|
1799
|
+
* You include group-level validators as the second arg, or group-level async
|
|
1800
|
+
* validators as the third arg. These come in handy when you want to perform validation
|
|
1801
|
+
* that considers the value of more than one child control.
|
|
1802
|
+
*
|
|
1803
|
+
* ```ts
|
|
1804
|
+
* const form = new FormGroup({
|
|
1805
|
+
* password: new FormControl('', Validators.minLength(2)),
|
|
1806
|
+
* passwordConfirm: new FormControl('', Validators.minLength(2)),
|
|
1807
|
+
* }, passwordMatchValidator);
|
|
1808
|
+
*
|
|
1809
|
+
*
|
|
1810
|
+
* function passwordMatchValidator(g: FormGroup) {
|
|
1811
|
+
* return g.get('password').value === g.get('passwordConfirm').value
|
|
1812
|
+
* ? null : {'mismatch': true};
|
|
1813
|
+
* }
|
|
1814
|
+
* ```
|
|
1815
|
+
*
|
|
1816
|
+
* Like `FormControl` instances, you choose to pass in
|
|
1817
|
+
* validators and async validators as part of an options object.
|
|
1818
|
+
*
|
|
1819
|
+
* ```ts
|
|
1820
|
+
* const form = new FormGroup({
|
|
1821
|
+
* password: new FormControl('')
|
|
1822
|
+
* passwordConfirm: new FormControl('')
|
|
1823
|
+
* }, { validators: passwordMatchValidator, asyncValidators: otherValidator });
|
|
1824
|
+
* ```
|
|
1825
|
+
*
|
|
1826
|
+
* ### Set the updateOn property for all controls in a form group
|
|
1827
|
+
*
|
|
1828
|
+
* The options object is used to set a default value for each child
|
|
1829
|
+
* control's `updateOn` property. If you set `updateOn` to `'blur'` at the
|
|
1830
|
+
* group level, all child controls default to 'blur', unless the child
|
|
1831
|
+
* has explicitly specified a different `updateOn` value.
|
|
1832
|
+
*
|
|
1833
|
+
* ```ts
|
|
1834
|
+
* const c = new FormGroup({
|
|
1835
|
+
* one: new FormControl()
|
|
1836
|
+
* }, { updateOn: 'blur' });
|
|
1837
|
+
* ```
|
|
1838
|
+
*
|
|
1839
|
+
* ### Using a FormGroup with optional controls
|
|
1840
|
+
*
|
|
1841
|
+
* It is possible to have optional controls in a FormGroup. An optional control can be removed later
|
|
1842
|
+
* using `removeControl`, and can be omitted when calling `reset`. Optional controls must be
|
|
1843
|
+
* declared optional in the group's type.
|
|
1844
|
+
*
|
|
1845
|
+
* ```ts
|
|
1846
|
+
* const c = new FormGroup<{one?: FormControl<string>}>({
|
|
1847
|
+
* one: new FormControl('')
|
|
1848
|
+
* });
|
|
1780
1849
|
* ```
|
|
1781
1850
|
*
|
|
1851
|
+
* Notice that `c.value.one` has type `string|null|undefined`. This is because calling `c.reset({})`
|
|
1852
|
+
* without providing the optional key `one` will cause it to become `null`.
|
|
1853
|
+
*
|
|
1782
1854
|
* @publicApi
|
|
1783
1855
|
*/
|
|
1784
|
-
declare class
|
|
1785
|
-
[
|
|
1786
|
-
}> {
|
|
1787
|
-
}
|
|
1788
|
-
interface FormRecord<TControl> {
|
|
1856
|
+
declare class FormGroup<TControl extends {
|
|
1857
|
+
[K in keyof TControl]: AbstractControl<any>;
|
|
1858
|
+
} = any> extends AbstractControl<ɵTypedOrUntyped<TControl, ɵFormGroupValue<TControl>, any>, ɵTypedOrUntyped<TControl, ɵFormGroupRawValue<TControl>, any>, ɵTypedOrUntyped<TControl, ɵFormGroupArgumentValue<TControl>, any>> {
|
|
1789
1859
|
/**
|
|
1790
|
-
*
|
|
1860
|
+
* Creates a new `FormGroup` instance.
|
|
1861
|
+
*
|
|
1862
|
+
* @param controls A collection of child controls. The key for each child is the name
|
|
1863
|
+
* under which it is registered.
|
|
1864
|
+
*
|
|
1865
|
+
* @param validatorOrOpts A synchronous validator function, or an array of
|
|
1866
|
+
* such functions, or an `AbstractControlOptions` object that contains validation functions
|
|
1867
|
+
* and a validation trigger.
|
|
1868
|
+
*
|
|
1869
|
+
* @param asyncValidator A single async validator or array of async validator functions
|
|
1791
1870
|
*
|
|
1792
|
-
* See `FormGroup#registerControl` for additional information.
|
|
1793
1871
|
*/
|
|
1794
|
-
|
|
1872
|
+
constructor(controls: TControl, validatorOrOpts?: ValidatorFn | ValidatorFn[] | AbstractControlOptions | null, asyncValidator?: AsyncValidatorFn | AsyncValidatorFn[] | null);
|
|
1873
|
+
controls: ɵTypedOrUntyped<TControl, TControl, {
|
|
1874
|
+
[key: string]: AbstractControl<any>;
|
|
1875
|
+
}>;
|
|
1795
1876
|
/**
|
|
1796
|
-
*
|
|
1877
|
+
* Registers a control with the group's list of controls. In a strongly-typed group, the control
|
|
1878
|
+
* must be in the group's type (possibly as an optional key).
|
|
1797
1879
|
*
|
|
1798
|
-
*
|
|
1880
|
+
* This method does not update the value or validity of the control.
|
|
1881
|
+
* Use {@link FormGroup#addControl addControl} instead.
|
|
1882
|
+
*
|
|
1883
|
+
* @param name The control name to register in the collection
|
|
1884
|
+
* @param control Provides the control for the given name
|
|
1799
1885
|
*/
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1886
|
+
registerControl<K extends string & keyof TControl>(name: K, control: TControl[K]): TControl[K];
|
|
1887
|
+
registerControl(this: FormGroup<{
|
|
1888
|
+
[key: string]: AbstractControl<any>;
|
|
1889
|
+
}>, name: string, control: AbstractControl<any>): AbstractControl<any>;
|
|
1803
1890
|
/**
|
|
1804
|
-
*
|
|
1891
|
+
* Add a control to this group. In a strongly-typed group, the control must be in the group's type
|
|
1892
|
+
* (possibly as an optional key).
|
|
1805
1893
|
*
|
|
1806
|
-
*
|
|
1894
|
+
* If a control with a given name already exists, it would *not* be replaced with a new one.
|
|
1895
|
+
* If you want to replace an existing control, use the {@link FormGroup#setControl setControl}
|
|
1896
|
+
* method instead. This method also updates the value and validity of the control.
|
|
1897
|
+
*
|
|
1898
|
+
* @param name The control name to add to the collection
|
|
1899
|
+
* @param control Provides the control for the given name
|
|
1900
|
+
* @param options Specifies whether this FormGroup instance should emit events after a new
|
|
1901
|
+
* control is added.
|
|
1902
|
+
* * `emitEvent`: When true or not supplied (the default), both the `statusChanges` and
|
|
1903
|
+
* `valueChanges` observables emit events with the latest status and value when the control is
|
|
1904
|
+
* added. When false, no events are emitted.
|
|
1807
1905
|
*/
|
|
1808
|
-
|
|
1906
|
+
addControl(this: FormGroup<{
|
|
1907
|
+
[key: string]: AbstractControl<any>;
|
|
1908
|
+
}>, name: string, control: AbstractControl, options?: {
|
|
1809
1909
|
emitEvent?: boolean;
|
|
1810
1910
|
}): void;
|
|
1811
|
-
|
|
1812
|
-
* Replace an existing control.
|
|
1813
|
-
*
|
|
1814
|
-
* See `FormGroup#setControl` for additional information.
|
|
1815
|
-
*/
|
|
1816
|
-
setControl(name: string, control: TControl, options?: {
|
|
1911
|
+
addControl<K extends string & keyof TControl>(name: K, control: Required<TControl>[K], options?: {
|
|
1817
1912
|
emitEvent?: boolean;
|
|
1818
1913
|
}): void;
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1914
|
+
removeControl(this: FormGroup<{
|
|
1915
|
+
[key: string]: AbstractControl<any>;
|
|
1916
|
+
}>, name: string, options?: {
|
|
1917
|
+
emitEvent?: boolean;
|
|
1918
|
+
}): void;
|
|
1919
|
+
removeControl<S extends string>(name: ɵOptionalKeys<TControl> & S, options?: {
|
|
1920
|
+
emitEvent?: boolean;
|
|
1921
|
+
}): void;
|
|
1922
|
+
/**
|
|
1923
|
+
* Replace an existing control. In a strongly-typed group, the control must be in the group's type
|
|
1924
|
+
* (possibly as an optional key).
|
|
1925
|
+
*
|
|
1926
|
+
* If a control with a given name does not exist in this `FormGroup`, it will be added.
|
|
1927
|
+
*
|
|
1928
|
+
* @param name The control name to replace in the collection
|
|
1929
|
+
* @param control Provides the control for the given name
|
|
1930
|
+
* @param options Specifies whether this FormGroup instance should emit events after an
|
|
1931
|
+
* existing control is replaced.
|
|
1932
|
+
* * `emitEvent`: When true or not supplied (the default), both the `statusChanges` and
|
|
1933
|
+
* `valueChanges` observables emit events with the latest status and value when the control is
|
|
1934
|
+
* replaced with a new one. When false, no events are emitted.
|
|
1823
1935
|
*/
|
|
1824
|
-
|
|
1936
|
+
setControl<K extends string & keyof TControl>(name: K, control: TControl[K], options?: {
|
|
1937
|
+
emitEvent?: boolean;
|
|
1938
|
+
}): void;
|
|
1939
|
+
setControl(this: FormGroup<{
|
|
1940
|
+
[key: string]: AbstractControl<any>;
|
|
1941
|
+
}>, name: string, control: AbstractControl, options?: {
|
|
1942
|
+
emitEvent?: boolean;
|
|
1943
|
+
}): void;
|
|
1825
1944
|
/**
|
|
1826
|
-
*
|
|
1945
|
+
* Check whether there is an enabled control with the given name in the group.
|
|
1946
|
+
*
|
|
1947
|
+
* Reports false for disabled controls. If you'd like to check for existence in the group
|
|
1948
|
+
* only, use {@link AbstractControl#get get} instead.
|
|
1949
|
+
*
|
|
1950
|
+
* @param controlName The control name to check for existence in the collection
|
|
1951
|
+
*
|
|
1952
|
+
* @returns false for disabled controls, true otherwise.
|
|
1953
|
+
*/
|
|
1954
|
+
contains<K extends string>(controlName: K): boolean;
|
|
1955
|
+
contains(this: FormGroup<{
|
|
1956
|
+
[key: string]: AbstractControl<any>;
|
|
1957
|
+
}>, controlName: string): boolean;
|
|
1958
|
+
/**
|
|
1959
|
+
* Sets the value of the `FormGroup`. It accepts an object that matches
|
|
1827
1960
|
* the structure of the group, with control names as keys.
|
|
1828
1961
|
*
|
|
1829
|
-
*
|
|
1962
|
+
* @usageNotes
|
|
1963
|
+
* ### Set the complete value for the form group
|
|
1964
|
+
*
|
|
1965
|
+
* ```ts
|
|
1966
|
+
* const form = new FormGroup({
|
|
1967
|
+
* first: new FormControl(),
|
|
1968
|
+
* last: new FormControl()
|
|
1969
|
+
* });
|
|
1970
|
+
*
|
|
1971
|
+
* console.log(form.value); // {first: null, last: null}
|
|
1972
|
+
*
|
|
1973
|
+
* form.setValue({first: 'Nancy', last: 'Drew'});
|
|
1974
|
+
* console.log(form.value); // {first: 'Nancy', last: 'Drew'}
|
|
1975
|
+
* ```
|
|
1976
|
+
*
|
|
1977
|
+
* @throws When strict checks fail, such as setting the value of a control
|
|
1978
|
+
* that doesn't exist or if you exclude a value of a control that does exist.
|
|
1979
|
+
*
|
|
1980
|
+
* @param value The new value for the control that matches the structure of the group.
|
|
1981
|
+
* @param options Configuration options that determine how the control propagates changes
|
|
1982
|
+
* and emits events after the value changes.
|
|
1983
|
+
* The configuration options are passed to the {@link AbstractControl#updateValueAndValidity
|
|
1984
|
+
* updateValueAndValidity} method.
|
|
1985
|
+
*
|
|
1986
|
+
* * `onlySelf`: When true, each change only affects this control, and not its parent. Default is
|
|
1987
|
+
* false.
|
|
1988
|
+
* * `emitEvent`: When true or not supplied (the default), both the `statusChanges` and
|
|
1989
|
+
* `valueChanges`
|
|
1990
|
+
* observables emit events with the latest status and value when the control value is updated.
|
|
1991
|
+
* When false, no events are emitted.
|
|
1830
1992
|
*/
|
|
1831
|
-
setValue(value: {
|
|
1832
|
-
[key: string]: ɵRawValue<TControl>;
|
|
1833
|
-
}, options?: {
|
|
1993
|
+
setValue(value: ɵFormGroupRawValue<TControl>, options?: {
|
|
1834
1994
|
onlySelf?: boolean;
|
|
1835
1995
|
emitEvent?: boolean;
|
|
1836
1996
|
}): void;
|
|
1837
1997
|
/**
|
|
1838
|
-
* Patches the value of the `
|
|
1998
|
+
* Patches the value of the `FormGroup`. It accepts an object with control
|
|
1839
1999
|
* names as keys, and does its best to match the values to the correct controls
|
|
1840
2000
|
* in the group.
|
|
1841
2001
|
*
|
|
1842
|
-
*
|
|
2002
|
+
* It accepts both super-sets and sub-sets of the group without throwing an error.
|
|
2003
|
+
*
|
|
2004
|
+
* @usageNotes
|
|
2005
|
+
* ### Patch the value for a form group
|
|
2006
|
+
*
|
|
2007
|
+
* ```ts
|
|
2008
|
+
* const form = new FormGroup({
|
|
2009
|
+
* first: new FormControl(),
|
|
2010
|
+
* last: new FormControl()
|
|
2011
|
+
* });
|
|
2012
|
+
* console.log(form.value); // {first: null, last: null}
|
|
2013
|
+
*
|
|
2014
|
+
* form.patchValue({first: 'Nancy'});
|
|
2015
|
+
* console.log(form.value); // {first: 'Nancy', last: null}
|
|
2016
|
+
* ```
|
|
2017
|
+
*
|
|
2018
|
+
* @param value The object that matches the structure of the group.
|
|
2019
|
+
* @param options Configuration options that determine how the control propagates changes and
|
|
2020
|
+
* emits events after the value is patched.
|
|
2021
|
+
* * `onlySelf`: When true, each change only affects this control and not its parent. Default is
|
|
2022
|
+
* true.
|
|
2023
|
+
* * `emitEvent`: When true or not supplied (the default), both the `statusChanges` and
|
|
2024
|
+
* `valueChanges` observables emit events with the latest status and value when the control value
|
|
2025
|
+
* is updated. When false, no events are emitted. The configuration options are passed to
|
|
2026
|
+
* the {@link AbstractControl#updateValueAndValidity updateValueAndValidity} method.
|
|
1843
2027
|
*/
|
|
1844
|
-
patchValue(value: {
|
|
1845
|
-
[key: string]: ɵValue<TControl>;
|
|
1846
|
-
}, options?: {
|
|
2028
|
+
patchValue(value: ɵFormGroupValue<TControl>, options?: {
|
|
1847
2029
|
onlySelf?: boolean;
|
|
1848
2030
|
emitEvent?: boolean;
|
|
1849
2031
|
}): void;
|
|
1850
2032
|
/**
|
|
1851
|
-
* Resets the `
|
|
1852
|
-
* the value of all descendants to null.
|
|
2033
|
+
* Resets the `FormGroup`, marks all descendants `pristine` and `untouched` and sets
|
|
2034
|
+
* the value of all descendants to their default values, or null if no defaults were provided.
|
|
1853
2035
|
*
|
|
1854
|
-
*
|
|
2036
|
+
* You reset to a specific form state by passing in a map of states
|
|
2037
|
+
* that matches the structure of your form, with control names as keys. The state
|
|
2038
|
+
* is a standalone value or a form state object with both a value and a disabled
|
|
2039
|
+
* status.
|
|
2040
|
+
*
|
|
2041
|
+
* @param value Resets the control with an initial value,
|
|
2042
|
+
* or an object that defines the initial value and disabled state.
|
|
2043
|
+
*
|
|
2044
|
+
* @param options Configuration options that determine how the control propagates changes
|
|
2045
|
+
* and emits events when the group is reset.
|
|
2046
|
+
* * `onlySelf`: When true, each change only affects this control, and not its parent. Default is
|
|
2047
|
+
* false.
|
|
2048
|
+
* * `emitEvent`: When true or not supplied (the default), both the `statusChanges` and
|
|
2049
|
+
* `valueChanges`
|
|
2050
|
+
* observables emit events with the latest status and value when the control is reset.
|
|
2051
|
+
* When false, no events are emitted.
|
|
2052
|
+
* The configuration options are passed to the {@link AbstractControl#updateValueAndValidity
|
|
2053
|
+
* updateValueAndValidity} method.
|
|
2054
|
+
*
|
|
2055
|
+
* @usageNotes
|
|
2056
|
+
*
|
|
2057
|
+
* ### Reset the form group values
|
|
2058
|
+
*
|
|
2059
|
+
* ```ts
|
|
2060
|
+
* const form = new FormGroup({
|
|
2061
|
+
* first: new FormControl('first name'),
|
|
2062
|
+
* last: new FormControl('last name')
|
|
2063
|
+
* });
|
|
2064
|
+
*
|
|
2065
|
+
* console.log(form.value); // {first: 'first name', last: 'last name'}
|
|
2066
|
+
*
|
|
2067
|
+
* form.reset({ first: 'name', last: 'last name' });
|
|
2068
|
+
*
|
|
2069
|
+
* console.log(form.value); // {first: 'name', last: 'last name'}
|
|
2070
|
+
* ```
|
|
2071
|
+
*
|
|
2072
|
+
* ### Reset the form group values and disabled status
|
|
2073
|
+
*
|
|
2074
|
+
* ```ts
|
|
2075
|
+
* const form = new FormGroup({
|
|
2076
|
+
* first: new FormControl('first name'),
|
|
2077
|
+
* last: new FormControl('last name')
|
|
2078
|
+
* });
|
|
2079
|
+
*
|
|
2080
|
+
* form.reset({
|
|
2081
|
+
* first: {value: 'name', disabled: true},
|
|
2082
|
+
* last: 'last'
|
|
2083
|
+
* });
|
|
2084
|
+
*
|
|
2085
|
+
* console.log(form.value); // {last: 'last'}
|
|
2086
|
+
* console.log(form.get('first').status); // 'DISABLED'
|
|
2087
|
+
* ```
|
|
1855
2088
|
*/
|
|
1856
|
-
reset(value?: {
|
|
1857
|
-
[key: string]: ɵValue<TControl>;
|
|
1858
|
-
}, options?: {
|
|
2089
|
+
reset(value?: ɵTypedOrUntyped<TControl, ɵFormGroupArgumentValue<TControl>, any>, options?: {
|
|
1859
2090
|
onlySelf?: boolean;
|
|
1860
2091
|
emitEvent?: boolean;
|
|
1861
2092
|
}): void;
|
|
1862
2093
|
/**
|
|
1863
|
-
* The aggregate value of the `
|
|
2094
|
+
* The aggregate value of the `FormGroup`, including any disabled controls.
|
|
1864
2095
|
*
|
|
1865
|
-
*
|
|
2096
|
+
* Retrieves all values regardless of disabled status.
|
|
1866
2097
|
*/
|
|
1867
|
-
getRawValue():
|
|
1868
|
-
|
|
1869
|
-
|
|
2098
|
+
getRawValue(): ɵTypedOrUntyped<TControl, ɵFormGroupRawValue<TControl>, any>;
|
|
2099
|
+
}
|
|
2100
|
+
interface UntypedFormGroupCtor {
|
|
2101
|
+
new (controls: {
|
|
2102
|
+
[key: string]: AbstractControl;
|
|
2103
|
+
}, validatorOrOpts?: ValidatorFn | ValidatorFn[] | AbstractControlOptions | null, asyncValidator?: AsyncValidatorFn | AsyncValidatorFn[] | null): UntypedFormGroup;
|
|
2104
|
+
/**
|
|
2105
|
+
* The presence of an explicit `prototype` property provides backwards-compatibility for apps that
|
|
2106
|
+
* manually inspect the prototype chain.
|
|
2107
|
+
*/
|
|
2108
|
+
prototype: FormGroup<any>;
|
|
1870
2109
|
}
|
|
2110
|
+
/**
|
|
2111
|
+
* UntypedFormGroup is a non-strongly-typed version of `FormGroup`.
|
|
2112
|
+
*/
|
|
2113
|
+
type UntypedFormGroup = FormGroup<any>;
|
|
2114
|
+
declare const UntypedFormGroup: UntypedFormGroupCtor;
|
|
1871
2115
|
/**
|
|
1872
2116
|
* @description
|
|
1873
|
-
* Asserts that the given control is an instance of `
|
|
2117
|
+
* Asserts that the given control is an instance of `FormGroup`
|
|
1874
2118
|
*
|
|
1875
2119
|
* @publicApi
|
|
1876
2120
|
*/
|
|
1877
|
-
declare const
|
|
1878
|
-
|
|
2121
|
+
declare const isFormGroup: (control: unknown) => control is FormGroup;
|
|
1879
2122
|
/**
|
|
1880
|
-
*
|
|
1881
|
-
*
|
|
2123
|
+
* Tracks the value and validity state of a collection of `FormControl` instances, each of which has
|
|
2124
|
+
* the same value type.
|
|
1882
2125
|
*
|
|
1883
|
-
*
|
|
1884
|
-
*
|
|
1885
|
-
* * **INVALID**: Reports that a control is invalid, meaning that an error exists in the input
|
|
1886
|
-
* value.
|
|
1887
|
-
* * **PENDING**: Reports that a control is pending, meaning that async validation is
|
|
1888
|
-
* occurring and errors are not yet available for the input value.
|
|
1889
|
-
* * **DISABLED**: Reports that a control is
|
|
1890
|
-
* disabled, meaning that the control is exempt from ancestor calculations of validity or value.
|
|
2126
|
+
* `FormRecord` is very similar to {@link FormGroup}, except it can be used with a dynamic keys,
|
|
2127
|
+
* with controls added and removed as needed.
|
|
1891
2128
|
*
|
|
1892
|
-
*
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
*
|
|
2129
|
+
* `FormRecord` accepts one generic argument, which describes the type of the controls it contains.
|
|
2130
|
+
*
|
|
2131
|
+
* @usageNotes
|
|
2132
|
+
*
|
|
2133
|
+
* ```ts
|
|
2134
|
+
* let numbers = new FormRecord({bill: new FormControl('415-123-456')});
|
|
2135
|
+
* numbers.addControl('bob', new FormControl('415-234-567'));
|
|
2136
|
+
* numbers.removeControl('bill');
|
|
2137
|
+
* ```
|
|
1897
2138
|
*
|
|
1898
2139
|
* @publicApi
|
|
1899
2140
|
*/
|
|
1900
|
-
declare
|
|
2141
|
+
declare class FormRecord<TControl extends AbstractControl = AbstractControl> extends FormGroup<{
|
|
2142
|
+
[key: string]: TControl;
|
|
2143
|
+
}> {
|
|
2144
|
+
}
|
|
2145
|
+
interface FormRecord<TControl> {
|
|
1901
2146
|
/**
|
|
1902
|
-
*
|
|
2147
|
+
* Registers a control with the records's list of controls.
|
|
1903
2148
|
*
|
|
1904
|
-
*
|
|
2149
|
+
* See `FormGroup#registerControl` for additional information.
|
|
1905
2150
|
*/
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
2151
|
+
registerControl(name: string, control: TControl): TControl;
|
|
2152
|
+
/**
|
|
2153
|
+
* Add a control to this group.
|
|
2154
|
+
*
|
|
2155
|
+
* See `FormGroup#addControl` for additional information.
|
|
2156
|
+
*/
|
|
2157
|
+
addControl(name: string, control: TControl, options?: {
|
|
2158
|
+
emitEvent?: boolean;
|
|
2159
|
+
}): void;
|
|
2160
|
+
/**
|
|
2161
|
+
* Remove a control from this group.
|
|
2162
|
+
*
|
|
2163
|
+
* See `FormGroup#removeControl` for additional information.
|
|
2164
|
+
*/
|
|
2165
|
+
removeControl(name: string, options?: {
|
|
2166
|
+
emitEvent?: boolean;
|
|
2167
|
+
}): void;
|
|
2168
|
+
/**
|
|
2169
|
+
* Replace an existing control.
|
|
2170
|
+
*
|
|
2171
|
+
* See `FormGroup#setControl` for additional information.
|
|
2172
|
+
*/
|
|
2173
|
+
setControl(name: string, control: TControl, options?: {
|
|
2174
|
+
emitEvent?: boolean;
|
|
2175
|
+
}): void;
|
|
2176
|
+
/**
|
|
2177
|
+
* Check whether there is an enabled control with the given name in the group.
|
|
2178
|
+
*
|
|
2179
|
+
* See `FormGroup#contains` for additional information.
|
|
2180
|
+
*/
|
|
2181
|
+
contains(controlName: string): boolean;
|
|
2182
|
+
/**
|
|
2183
|
+
* Sets the value of the `FormRecord`. It accepts an object that matches
|
|
2184
|
+
* the structure of the group, with control names as keys.
|
|
2185
|
+
*
|
|
2186
|
+
* See `FormGroup#setValue` for additional information.
|
|
2187
|
+
*/
|
|
2188
|
+
setValue(value: {
|
|
2189
|
+
[key: string]: ɵRawValue<TControl>;
|
|
2190
|
+
}, options?: {
|
|
2191
|
+
onlySelf?: boolean;
|
|
2192
|
+
emitEvent?: boolean;
|
|
2193
|
+
}): void;
|
|
2194
|
+
/**
|
|
2195
|
+
* Patches the value of the `FormRecord`. It accepts an object with control
|
|
2196
|
+
* names as keys, and does its best to match the values to the correct controls
|
|
2197
|
+
* in the group.
|
|
2198
|
+
*
|
|
2199
|
+
* See `FormGroup#patchValue` for additional information.
|
|
2200
|
+
*/
|
|
2201
|
+
patchValue(value: {
|
|
2202
|
+
[key: string]: ɵValue<TControl>;
|
|
2203
|
+
}, options?: {
|
|
2204
|
+
onlySelf?: boolean;
|
|
2205
|
+
emitEvent?: boolean;
|
|
2206
|
+
}): void;
|
|
2207
|
+
/**
|
|
2208
|
+
* Resets the `FormRecord`, marks all descendants `pristine` and `untouched` and sets
|
|
2209
|
+
* the value of all descendants to null.
|
|
2210
|
+
*
|
|
2211
|
+
* See `FormGroup#reset` for additional information.
|
|
2212
|
+
*/
|
|
2213
|
+
reset(value?: {
|
|
2214
|
+
[key: string]: ɵValue<TControl> | FormControlState<ɵValue<TControl>>;
|
|
2215
|
+
}, options?: {
|
|
2216
|
+
onlySelf?: boolean;
|
|
2217
|
+
emitEvent?: boolean;
|
|
2218
|
+
}): void;
|
|
2219
|
+
/**
|
|
2220
|
+
* The aggregate value of the `FormRecord`, including any disabled controls.
|
|
2221
|
+
*
|
|
2222
|
+
* See `FormGroup#getRawValue` for additional information.
|
|
2223
|
+
*/
|
|
2224
|
+
getRawValue(): {
|
|
2225
|
+
[key: string]: ɵRawValue<TControl>;
|
|
2226
|
+
};
|
|
2227
|
+
}
|
|
2228
|
+
/**
|
|
2229
|
+
* @description
|
|
2230
|
+
* Asserts that the given control is an instance of `FormRecord`
|
|
2231
|
+
*
|
|
2232
|
+
* @publicApi
|
|
2233
|
+
*/
|
|
2234
|
+
declare const isFormRecord: (control: unknown) => control is FormRecord;
|
|
2235
|
+
|
|
2236
|
+
/**
|
|
2237
|
+
* A form can have several different statuses. Each
|
|
2238
|
+
* possible status is returned as a string literal.
|
|
2239
|
+
*
|
|
2240
|
+
* * **VALID**: Reports that a control is valid, meaning that no errors exist in the input
|
|
2241
|
+
* value.
|
|
2242
|
+
* * **INVALID**: Reports that a control is invalid, meaning that an error exists in the input
|
|
2243
|
+
* value.
|
|
2244
|
+
* * **PENDING**: Reports that a control is pending, meaning that async validation is
|
|
2245
|
+
* occurring and errors are not yet available for the input value.
|
|
2246
|
+
* * **DISABLED**: Reports that a control is
|
|
2247
|
+
* disabled, meaning that the control is exempt from ancestor calculations of validity or value.
|
|
2248
|
+
*
|
|
2249
|
+
* @publicApi
|
|
2250
|
+
*/
|
|
2251
|
+
type FormControlStatus = 'VALID' | 'INVALID' | 'PENDING' | 'DISABLED';
|
|
2252
|
+
/**
|
|
2253
|
+
* Base class for every event sent by `AbstractControl.events()`
|
|
2254
|
+
*
|
|
2255
|
+
* @publicApi
|
|
2256
|
+
*/
|
|
2257
|
+
declare abstract class ControlEvent<T = any> {
|
|
2258
|
+
/**
|
|
2259
|
+
* Form control from which this event is originated.
|
|
2260
|
+
*
|
|
2261
|
+
* Note: the type of the control can't be infered from T as the event can be emitted by any of child controls
|
|
2262
|
+
*/
|
|
2263
|
+
abstract readonly source: AbstractControl<unknown>;
|
|
2264
|
+
}
|
|
2265
|
+
/**
|
|
2266
|
+
* Event fired when the value of a control changes.
|
|
2267
|
+
*
|
|
2268
|
+
* @publicApi
|
|
2269
|
+
*/
|
|
2270
|
+
declare class ValueChangeEvent<T> extends ControlEvent<T> {
|
|
2271
|
+
readonly value: T;
|
|
2272
|
+
readonly source: AbstractControl;
|
|
2273
|
+
constructor(value: T, source: AbstractControl);
|
|
2274
|
+
}
|
|
2275
|
+
/**
|
|
2276
|
+
* Event fired when the control's pristine state changes (pristine <=> dirty).
|
|
2277
|
+
*
|
|
2278
|
+
* @publicApi */
|
|
1922
2279
|
declare class PristineChangeEvent extends ControlEvent {
|
|
1923
2280
|
readonly pristine: boolean;
|
|
1924
2281
|
readonly source: AbstractControl;
|
|
@@ -2122,7 +2479,7 @@ type ɵGetProperty<T, K> = K extends string ? ɵGetProperty<T, ɵCoerceStrArrToN
|
|
|
2122
2479
|
*
|
|
2123
2480
|
* @publicApi
|
|
2124
2481
|
*/
|
|
2125
|
-
declare abstract class AbstractControl<TValue = any, TRawValue extends TValue = TValue> {
|
|
2482
|
+
declare abstract class AbstractControl<TValue = any, TRawValue extends TValue = TValue, TValueWithOptionalControlStates = any> {
|
|
2126
2483
|
private _parent;
|
|
2127
2484
|
private _asyncValidationSubscription;
|
|
2128
2485
|
/**
|
|
@@ -2634,7 +2991,7 @@ declare abstract class AbstractControl<TValue = any, TRawValue extends TValue =
|
|
|
2634
2991
|
/**
|
|
2635
2992
|
* Resets the control. Abstract method (implemented in sub-classes).
|
|
2636
2993
|
*/
|
|
2637
|
-
abstract reset(value?:
|
|
2994
|
+
abstract reset(value?: TValueWithOptionalControlStates, options?: Object): void;
|
|
2638
2995
|
/**
|
|
2639
2996
|
* The raw value of this control. For most control implementations, the raw value will include
|
|
2640
2997
|
* disabled children.
|
|
@@ -3111,356 +3468,6 @@ declare class RadioControlValueAccessor extends BuiltInControlValueAccessor impl
|
|
|
3111
3468
|
static ɵdir: i0.ɵɵDirectiveDeclaration<RadioControlValueAccessor, "input[type=radio][formControlName],input[type=radio][formControl],input[type=radio][ngModel]", never, { "name": { "alias": "name"; "required": false; }; "formControlName": { "alias": "formControlName"; "required": false; }; "value": { "alias": "value"; "required": false; }; }, {}, never, never, false, never>;
|
|
3112
3469
|
}
|
|
3113
3470
|
|
|
3114
|
-
/**
|
|
3115
|
-
* FormControlState is a boxed form value. It is an object with a `value` key and a `disabled` key.
|
|
3116
|
-
*
|
|
3117
|
-
* @publicApi
|
|
3118
|
-
*/
|
|
3119
|
-
interface FormControlState<T> {
|
|
3120
|
-
value: T;
|
|
3121
|
-
disabled: boolean;
|
|
3122
|
-
}
|
|
3123
|
-
/**
|
|
3124
|
-
* Interface for options provided to a `FormControl`.
|
|
3125
|
-
*
|
|
3126
|
-
* This interface extends all options from {@link AbstractControlOptions}, plus some options
|
|
3127
|
-
* unique to `FormControl`.
|
|
3128
|
-
*
|
|
3129
|
-
* @publicApi
|
|
3130
|
-
*/
|
|
3131
|
-
interface FormControlOptions extends AbstractControlOptions {
|
|
3132
|
-
/**
|
|
3133
|
-
* @description
|
|
3134
|
-
* Whether to use the initial value used to construct the `FormControl` as its default value
|
|
3135
|
-
* as well. If this option is false or not provided, the default value of a FormControl is `null`.
|
|
3136
|
-
* When a FormControl is reset without an explicit value, its value reverts to
|
|
3137
|
-
* its default value.
|
|
3138
|
-
*/
|
|
3139
|
-
nonNullable?: boolean;
|
|
3140
|
-
/**
|
|
3141
|
-
* @deprecated Use `nonNullable` instead.
|
|
3142
|
-
*/
|
|
3143
|
-
initialValueIsDefault?: boolean;
|
|
3144
|
-
}
|
|
3145
|
-
/**
|
|
3146
|
-
* Various available constructors for `FormControl`.
|
|
3147
|
-
* Do not use this interface directly. Instead, use `FormControl`:
|
|
3148
|
-
* ```ts
|
|
3149
|
-
* const fc = new FormControl('foo');
|
|
3150
|
-
* ```
|
|
3151
|
-
* This symbol is prefixed with ɵ to make plain that it is an internal symbol.
|
|
3152
|
-
*/
|
|
3153
|
-
interface ɵFormControlCtor {
|
|
3154
|
-
/**
|
|
3155
|
-
* Construct a FormControl with no initial value or validators.
|
|
3156
|
-
*/
|
|
3157
|
-
new (): FormControl<any>;
|
|
3158
|
-
/**
|
|
3159
|
-
* Creates a new `FormControl` instance.
|
|
3160
|
-
*
|
|
3161
|
-
* @param value Initializes the control with an initial value,
|
|
3162
|
-
* or an object that defines the initial value and disabled state.
|
|
3163
|
-
*
|
|
3164
|
-
* @param opts A `FormControlOptions` object that contains validation functions and a
|
|
3165
|
-
* validation trigger. `nonNullable` have to be `true`
|
|
3166
|
-
*/
|
|
3167
|
-
new <T = any>(value: FormControlState<T> | T, opts: FormControlOptions & {
|
|
3168
|
-
nonNullable: true;
|
|
3169
|
-
}): FormControl<T>;
|
|
3170
|
-
/**
|
|
3171
|
-
* @deprecated Use `nonNullable` instead.
|
|
3172
|
-
*/
|
|
3173
|
-
new <T = any>(value: FormControlState<T> | T, opts: FormControlOptions & {
|
|
3174
|
-
initialValueIsDefault: true;
|
|
3175
|
-
}): FormControl<T>;
|
|
3176
|
-
/**
|
|
3177
|
-
* @deprecated When passing an `options` argument, the `asyncValidator` argument has no effect.
|
|
3178
|
-
*/
|
|
3179
|
-
new <T = any>(value: FormControlState<T> | T, opts: FormControlOptions, asyncValidator: AsyncValidatorFn | AsyncValidatorFn[]): FormControl<T | null>;
|
|
3180
|
-
/**
|
|
3181
|
-
* Creates a new `FormControl` instance.
|
|
3182
|
-
*
|
|
3183
|
-
* @param value Initializes the control with an initial value,
|
|
3184
|
-
* or an object that defines the initial value and disabled state.
|
|
3185
|
-
*
|
|
3186
|
-
* @param validatorOrOpts A synchronous validator function, or an array of
|
|
3187
|
-
* such functions, or a `FormControlOptions` object that contains validation functions
|
|
3188
|
-
* and a validation trigger.
|
|
3189
|
-
*
|
|
3190
|
-
* @param asyncValidator A single async validator or array of async validator functions
|
|
3191
|
-
*/
|
|
3192
|
-
new <T = any>(value: FormControlState<T> | T, validatorOrOpts?: ValidatorFn | ValidatorFn[] | FormControlOptions | null, asyncValidator?: AsyncValidatorFn | AsyncValidatorFn[] | null): FormControl<T | null>;
|
|
3193
|
-
/**
|
|
3194
|
-
* The presence of an explicit `prototype` property provides backwards-compatibility for apps that
|
|
3195
|
-
* manually inspect the prototype chain.
|
|
3196
|
-
*/
|
|
3197
|
-
prototype: FormControl<any>;
|
|
3198
|
-
}
|
|
3199
|
-
/**
|
|
3200
|
-
* Tracks the value and validation status of an individual form control.
|
|
3201
|
-
*
|
|
3202
|
-
* This is one of the four fundamental building blocks of Angular forms, along with
|
|
3203
|
-
* `FormGroup`, `FormArray` and `FormRecord`. It extends the `AbstractControl` class that
|
|
3204
|
-
* implements most of the base functionality for accessing the value, validation status,
|
|
3205
|
-
* user interactions and events.
|
|
3206
|
-
*
|
|
3207
|
-
* `FormControl` takes a single generic argument, which describes the type of its value. This
|
|
3208
|
-
* argument always implicitly includes `null` because the control can be reset. To change this
|
|
3209
|
-
* behavior, set `nonNullable` or see the usage notes below.
|
|
3210
|
-
*
|
|
3211
|
-
* See [usage examples below](#usage-notes).
|
|
3212
|
-
*
|
|
3213
|
-
* @see {@link AbstractControl}
|
|
3214
|
-
* @see [Reactive Forms Guide](guide/forms/reactive-forms)
|
|
3215
|
-
* @see [Usage Notes](#usage-notes)
|
|
3216
|
-
*
|
|
3217
|
-
* @publicApi
|
|
3218
|
-
*
|
|
3219
|
-
* @overriddenImplementation ɵFormControlCtor
|
|
3220
|
-
*
|
|
3221
|
-
* @usageNotes
|
|
3222
|
-
*
|
|
3223
|
-
* ### Initializing Form Controls
|
|
3224
|
-
*
|
|
3225
|
-
* Instantiate a `FormControl`, with an initial value.
|
|
3226
|
-
*
|
|
3227
|
-
* ```ts
|
|
3228
|
-
* const control = new FormControl('some value');
|
|
3229
|
-
* console.log(control.value); // 'some value'
|
|
3230
|
-
* ```
|
|
3231
|
-
*
|
|
3232
|
-
* The following example initializes the control with a form state object. The `value`
|
|
3233
|
-
* and `disabled` keys are required in this case.
|
|
3234
|
-
*
|
|
3235
|
-
* ```ts
|
|
3236
|
-
* const control = new FormControl({ value: 'n/a', disabled: true });
|
|
3237
|
-
* console.log(control.value); // 'n/a'
|
|
3238
|
-
* console.log(control.status); // 'DISABLED'
|
|
3239
|
-
* ```
|
|
3240
|
-
*
|
|
3241
|
-
* The following example initializes the control with a synchronous validator.
|
|
3242
|
-
*
|
|
3243
|
-
* ```ts
|
|
3244
|
-
* const control = new FormControl('', Validators.required);
|
|
3245
|
-
* console.log(control.value); // ''
|
|
3246
|
-
* console.log(control.status); // 'INVALID'
|
|
3247
|
-
* ```
|
|
3248
|
-
*
|
|
3249
|
-
* The following example initializes the control using an options object.
|
|
3250
|
-
*
|
|
3251
|
-
* ```ts
|
|
3252
|
-
* const control = new FormControl('', {
|
|
3253
|
-
* validators: Validators.required,
|
|
3254
|
-
* asyncValidators: myAsyncValidator
|
|
3255
|
-
* });
|
|
3256
|
-
* ```
|
|
3257
|
-
*
|
|
3258
|
-
* ### The single type argument
|
|
3259
|
-
*
|
|
3260
|
-
* `FormControl` accepts a generic argument, which describes the type of its value.
|
|
3261
|
-
* In most cases, this argument will be inferred.
|
|
3262
|
-
*
|
|
3263
|
-
* If you are initializing the control to `null`, or you otherwise wish to provide a
|
|
3264
|
-
* wider type, you may specify the argument explicitly:
|
|
3265
|
-
*
|
|
3266
|
-
* ```ts
|
|
3267
|
-
* let fc = new FormControl<string|null>(null);
|
|
3268
|
-
* fc.setValue('foo');
|
|
3269
|
-
* ```
|
|
3270
|
-
*
|
|
3271
|
-
* You might notice that `null` is always added to the type of the control.
|
|
3272
|
-
* This is because the control will become `null` if you call `reset`. You can change
|
|
3273
|
-
* this behavior by setting `{nonNullable: true}`.
|
|
3274
|
-
*
|
|
3275
|
-
* ### Configure the control to update on a blur event
|
|
3276
|
-
*
|
|
3277
|
-
* Set the `updateOn` option to `'blur'` to update on the blur `event`.
|
|
3278
|
-
*
|
|
3279
|
-
* ```ts
|
|
3280
|
-
* const control = new FormControl('', { updateOn: 'blur' });
|
|
3281
|
-
* ```
|
|
3282
|
-
*
|
|
3283
|
-
* ### Configure the control to update on a submit event
|
|
3284
|
-
*
|
|
3285
|
-
* Set the `updateOn` option to `'submit'` to update on a submit `event`.
|
|
3286
|
-
*
|
|
3287
|
-
* ```ts
|
|
3288
|
-
* const control = new FormControl('', { updateOn: 'submit' });
|
|
3289
|
-
* ```
|
|
3290
|
-
*
|
|
3291
|
-
* ### Reset the control back to a specific value
|
|
3292
|
-
*
|
|
3293
|
-
* You reset to a specific form state by passing through a standalone
|
|
3294
|
-
* value or a form state object that contains both a value and a disabled state
|
|
3295
|
-
* (these are the only two properties that cannot be calculated).
|
|
3296
|
-
*
|
|
3297
|
-
* ```ts
|
|
3298
|
-
* const control = new FormControl('Nancy');
|
|
3299
|
-
*
|
|
3300
|
-
* console.log(control.value); // 'Nancy'
|
|
3301
|
-
*
|
|
3302
|
-
* control.reset('Drew');
|
|
3303
|
-
*
|
|
3304
|
-
* console.log(control.value); // 'Drew'
|
|
3305
|
-
* ```
|
|
3306
|
-
*
|
|
3307
|
-
* ### Reset the control to its initial value
|
|
3308
|
-
*
|
|
3309
|
-
* If you wish to always reset the control to its initial value (instead of null),
|
|
3310
|
-
* you can pass the `nonNullable` option:
|
|
3311
|
-
*
|
|
3312
|
-
* ```ts
|
|
3313
|
-
* const control = new FormControl('Nancy', {nonNullable: true});
|
|
3314
|
-
*
|
|
3315
|
-
* console.log(control.value); // 'Nancy'
|
|
3316
|
-
*
|
|
3317
|
-
* control.reset();
|
|
3318
|
-
*
|
|
3319
|
-
* console.log(control.value); // 'Nancy'
|
|
3320
|
-
* ```
|
|
3321
|
-
*
|
|
3322
|
-
* ### Reset the control back to an initial value and disabled
|
|
3323
|
-
*
|
|
3324
|
-
* ```ts
|
|
3325
|
-
* const control = new FormControl('Nancy');
|
|
3326
|
-
*
|
|
3327
|
-
* console.log(control.value); // 'Nancy'
|
|
3328
|
-
* console.log(control.status); // 'VALID'
|
|
3329
|
-
*
|
|
3330
|
-
* control.reset({ value: 'Drew', disabled: true });
|
|
3331
|
-
*
|
|
3332
|
-
* console.log(control.value); // 'Drew'
|
|
3333
|
-
* console.log(control.status); // 'DISABLED'
|
|
3334
|
-
* ```
|
|
3335
|
-
*/
|
|
3336
|
-
interface FormControl<TValue = any> extends AbstractControl<TValue> {
|
|
3337
|
-
/**
|
|
3338
|
-
* The default value of this FormControl, used whenever the control is reset without an explicit
|
|
3339
|
-
* value. See {@link FormControlOptions#nonNullable} for more information on configuring
|
|
3340
|
-
* a default value.
|
|
3341
|
-
*/
|
|
3342
|
-
readonly defaultValue: TValue;
|
|
3343
|
-
/**
|
|
3344
|
-
* Sets a new value for the form control.
|
|
3345
|
-
*
|
|
3346
|
-
* @param value The new value for the control.
|
|
3347
|
-
* @param options Configuration options that determine how the control propagates changes
|
|
3348
|
-
* and emits events when the value changes.
|
|
3349
|
-
* The configuration options are passed to the {@link AbstractControl#updateValueAndValidity
|
|
3350
|
-
* updateValueAndValidity} method.
|
|
3351
|
-
*
|
|
3352
|
-
* * `onlySelf`: When true, each change only affects this control, and not its parent. Default is
|
|
3353
|
-
* false.
|
|
3354
|
-
* * `emitEvent`: When true or not supplied (the default), both the `statusChanges` and
|
|
3355
|
-
* `valueChanges`
|
|
3356
|
-
* observables emit events with the latest status and value when the control value is updated.
|
|
3357
|
-
* When false, no events are emitted.
|
|
3358
|
-
* * `emitModelToViewChange`: When true or not supplied (the default), each change triggers an
|
|
3359
|
-
* `onChange` event to
|
|
3360
|
-
* update the view.
|
|
3361
|
-
* * `emitViewToModelChange`: When true or not supplied (the default), each change triggers an
|
|
3362
|
-
* `ngModelChange`
|
|
3363
|
-
* event to update the model.
|
|
3364
|
-
*
|
|
3365
|
-
*/
|
|
3366
|
-
setValue(value: TValue, options?: {
|
|
3367
|
-
onlySelf?: boolean;
|
|
3368
|
-
emitEvent?: boolean;
|
|
3369
|
-
emitModelToViewChange?: boolean;
|
|
3370
|
-
emitViewToModelChange?: boolean;
|
|
3371
|
-
}): void;
|
|
3372
|
-
/**
|
|
3373
|
-
* Patches the value of a control.
|
|
3374
|
-
*
|
|
3375
|
-
* This function is functionally the same as {@link FormControl#setValue setValue} at this level.
|
|
3376
|
-
* It exists for symmetry with {@link FormGroup#patchValue patchValue} on `FormGroups` and
|
|
3377
|
-
* `FormArrays`, where it does behave differently.
|
|
3378
|
-
*
|
|
3379
|
-
* @see {@link FormControl#setValue} for options
|
|
3380
|
-
*/
|
|
3381
|
-
patchValue(value: TValue, options?: {
|
|
3382
|
-
onlySelf?: boolean;
|
|
3383
|
-
emitEvent?: boolean;
|
|
3384
|
-
emitModelToViewChange?: boolean;
|
|
3385
|
-
emitViewToModelChange?: boolean;
|
|
3386
|
-
}): void;
|
|
3387
|
-
/**
|
|
3388
|
-
* Resets the form control, marking it `pristine` and `untouched`, and resetting
|
|
3389
|
-
* the value. The new value will be the provided value (if passed), `null`, or the initial value
|
|
3390
|
-
* if `nonNullable` was set in the constructor via {@link FormControlOptions}.
|
|
3391
|
-
*
|
|
3392
|
-
* ```ts
|
|
3393
|
-
* // By default, the control will reset to null.
|
|
3394
|
-
* const dog = new FormControl('spot');
|
|
3395
|
-
* dog.reset(); // dog.value is null
|
|
3396
|
-
*
|
|
3397
|
-
* // If this flag is set, the control will instead reset to the initial value.
|
|
3398
|
-
* const cat = new FormControl('tabby', {nonNullable: true});
|
|
3399
|
-
* cat.reset(); // cat.value is "tabby"
|
|
3400
|
-
*
|
|
3401
|
-
* // A value passed to reset always takes precedence.
|
|
3402
|
-
* const fish = new FormControl('finn', {nonNullable: true});
|
|
3403
|
-
* fish.reset('bubble'); // fish.value is "bubble"
|
|
3404
|
-
* ```
|
|
3405
|
-
*
|
|
3406
|
-
* @param formState Resets the control with an initial value,
|
|
3407
|
-
* or an object that defines the initial value and disabled state.
|
|
3408
|
-
*
|
|
3409
|
-
* @param options Configuration options that determine how the control propagates changes
|
|
3410
|
-
* and emits events after the value changes.
|
|
3411
|
-
*
|
|
3412
|
-
* * `onlySelf`: When true, each change only affects this control, and not its parent. Default is
|
|
3413
|
-
* false.
|
|
3414
|
-
* * `emitEvent`: When true or not supplied (the default), both the `statusChanges` and
|
|
3415
|
-
* `valueChanges`
|
|
3416
|
-
* observables emit events with the latest status and value when the control is reset.
|
|
3417
|
-
* When false, no events are emitted.
|
|
3418
|
-
*
|
|
3419
|
-
*/
|
|
3420
|
-
reset(formState?: TValue | FormControlState<TValue>, options?: {
|
|
3421
|
-
onlySelf?: boolean;
|
|
3422
|
-
emitEvent?: boolean;
|
|
3423
|
-
}): void;
|
|
3424
|
-
/**
|
|
3425
|
-
* For a simple FormControl, the raw value is equivalent to the value.
|
|
3426
|
-
*/
|
|
3427
|
-
getRawValue(): TValue;
|
|
3428
|
-
/**
|
|
3429
|
-
* Register a listener for change events.
|
|
3430
|
-
*
|
|
3431
|
-
* @param fn The method that is called when the value changes
|
|
3432
|
-
*/
|
|
3433
|
-
registerOnChange(fn: Function): void;
|
|
3434
|
-
/**
|
|
3435
|
-
* Register a listener for disabled events.
|
|
3436
|
-
*
|
|
3437
|
-
* @param fn The method that is called when the disabled status changes.
|
|
3438
|
-
*/
|
|
3439
|
-
registerOnDisabledChange(fn: (isDisabled: boolean) => void): void;
|
|
3440
|
-
}
|
|
3441
|
-
declare const FormControl: ɵFormControlCtor;
|
|
3442
|
-
interface UntypedFormControlCtor {
|
|
3443
|
-
new (): UntypedFormControl;
|
|
3444
|
-
new (formState?: any, validatorOrOpts?: ValidatorFn | ValidatorFn[] | FormControlOptions | null, asyncValidator?: AsyncValidatorFn | AsyncValidatorFn[] | null): UntypedFormControl;
|
|
3445
|
-
/**
|
|
3446
|
-
* The presence of an explicit `prototype` property provides backwards-compatibility for apps that
|
|
3447
|
-
* manually inspect the prototype chain.
|
|
3448
|
-
*/
|
|
3449
|
-
prototype: FormControl<any>;
|
|
3450
|
-
}
|
|
3451
|
-
/**
|
|
3452
|
-
* UntypedFormControl is a non-strongly-typed version of `FormControl`.
|
|
3453
|
-
*/
|
|
3454
|
-
type UntypedFormControl = FormControl<any>;
|
|
3455
|
-
declare const UntypedFormControl: UntypedFormControlCtor;
|
|
3456
|
-
/**
|
|
3457
|
-
* @description
|
|
3458
|
-
* Asserts that the given control is an instance of `FormControl`
|
|
3459
|
-
*
|
|
3460
|
-
* @publicApi
|
|
3461
|
-
*/
|
|
3462
|
-
declare const isFormControl: (control: unknown) => control is FormControl;
|
|
3463
|
-
|
|
3464
3471
|
/**
|
|
3465
3472
|
* @description
|
|
3466
3473
|
* A base class for code shared between the `NgModelGroup` and `FormGroupName` directives.
|