1
|
/**
|
2
|
* @license Angular v4.4.6
|
3
|
* (c) 2010-2017 Google, Inc. https://angular.io/
|
4
|
* License: MIT
|
5
|
*/
|
6
|
import { Directive, ElementRef, EventEmitter, Host, Inject, Injectable, InjectionToken, Injector, Input, NgModule, Optional, Output, Renderer2, Self, SkipSelf, Version, forwardRef, ɵisObservable, ɵisPromise, ɵlooseIdentical } from '@angular/core';
|
7
|
import { forkJoin } from 'rxjs/observable/forkJoin';
|
8
|
import { fromPromise } from 'rxjs/observable/fromPromise';
|
9
|
import { map } from 'rxjs/operator/map';
|
10
|
import { ɵgetDOM } from '@angular/platform-browser';
|
11
|
|
12
|
/**
|
13
|
* @license
|
14
|
* Copyright Google Inc. All Rights Reserved.
|
15
|
*
|
16
|
* Use of this source code is governed by an MIT-style license that can be
|
17
|
* found in the LICENSE file at https://angular.io/license
|
18
|
*/
|
19
|
/**
|
20
|
* Base class for control directives.
|
21
|
*
|
22
|
* Only used internally in the forms module.
|
23
|
*
|
24
|
* \@stable
|
25
|
* @abstract
|
26
|
*/
|
27
|
class AbstractControlDirective {
|
28
|
/**
|
29
|
* The {\@link FormControl}, {\@link FormGroup}, or {\@link FormArray}
|
30
|
* that backs this directive. Most properties fall through to that
|
31
|
* instance.
|
32
|
* @abstract
|
33
|
* @return {?}
|
34
|
*/
|
35
|
control() { }
|
36
|
/**
|
37
|
* The value of the control.
|
38
|
* @return {?}
|
39
|
*/
|
40
|
get value() { return this.control ? this.control.value : null; }
|
41
|
/**
|
42
|
* A control is `valid` when its `status === VALID`.
|
43
|
*
|
44
|
* In order to have this status, the control must have passed all its
|
45
|
* validation checks.
|
46
|
* @return {?}
|
47
|
*/
|
48
|
get valid() { return this.control ? this.control.valid : null; }
|
49
|
/**
|
50
|
* A control is `invalid` when its `status === INVALID`.
|
51
|
*
|
52
|
* In order to have this status, the control must have failed
|
53
|
* at least one of its validation checks.
|
54
|
* @return {?}
|
55
|
*/
|
56
|
get invalid() { return this.control ? this.control.invalid : null; }
|
57
|
/**
|
58
|
* A control is `pending` when its `status === PENDING`.
|
59
|
*
|
60
|
* In order to have this status, the control must be in the
|
61
|
* middle of conducting a validation check.
|
62
|
* @return {?}
|
63
|
*/
|
64
|
get pending() { return this.control ? this.control.pending : null; }
|
65
|
/**
|
66
|
* A control is `disabled` when its `status === DISABLED`.
|
67
|
*
|
68
|
* Disabled controls are exempt from validation checks and
|
69
|
* are not included in the aggregate value of their ancestor
|
70
|
* controls.
|
71
|
* @return {?}
|
72
|
*/
|
73
|
get disabled() { return this.control ? this.control.disabled : null; }
|
74
|
/**
|
75
|
* A control is `enabled` as long as its `status !== DISABLED`.
|
76
|
*
|
77
|
* In other words, it has a status of `VALID`, `INVALID`, or
|
78
|
* `PENDING`.
|
79
|
* @return {?}
|
80
|
*/
|
81
|
get enabled() { return this.control ? this.control.enabled : null; }
|
82
|
/**
|
83
|
* Returns any errors generated by failing validation. If there
|
84
|
* are no errors, it will return null.
|
85
|
* @return {?}
|
86
|
*/
|
87
|
get errors() { return this.control ? this.control.errors : null; }
|
88
|
/**
|
89
|
* A control is `pristine` if the user has not yet changed
|
90
|
* the value in the UI.
|
91
|
*
|
92
|
* Note that programmatic changes to a control's value will
|
93
|
* *not* mark it dirty.
|
94
|
* @return {?}
|
95
|
*/
|
96
|
get pristine() { return this.control ? this.control.pristine : null; }
|
97
|
/**
|
98
|
* A control is `dirty` if the user has changed the value
|
99
|
* in the UI.
|
100
|
*
|
101
|
* Note that programmatic changes to a control's value will
|
102
|
* *not* mark it dirty.
|
103
|
* @return {?}
|
104
|
*/
|
105
|
get dirty() { return this.control ? this.control.dirty : null; }
|
106
|
/**
|
107
|
* A control is marked `touched` once the user has triggered
|
108
|
* a `blur` event on it.
|
109
|
* @return {?}
|
110
|
*/
|
111
|
get touched() { return this.control ? this.control.touched : null; }
|
112
|
/**
|
113
|
* A control is `untouched` if the user has not yet triggered
|
114
|
* a `blur` event on it.
|
115
|
* @return {?}
|
116
|
*/
|
117
|
get untouched() { return this.control ? this.control.untouched : null; }
|
118
|
/**
|
119
|
* Emits an event every time the validation status of the control
|
120
|
* is re-calculated.
|
121
|
* @return {?}
|
122
|
*/
|
123
|
get statusChanges() {
|
124
|
return this.control ? this.control.statusChanges : null;
|
125
|
}
|
126
|
/**
|
127
|
* Emits an event every time the value of the control changes, in
|
128
|
* the UI or programmatically.
|
129
|
* @return {?}
|
130
|
*/
|
131
|
get valueChanges() {
|
132
|
return this.control ? this.control.valueChanges : null;
|
133
|
}
|
134
|
/**
|
135
|
* Returns an array that represents the path from the top-level form
|
136
|
* to this control. Each index is the string name of the control on
|
137
|
* that level.
|
138
|
* @return {?}
|
139
|
*/
|
140
|
get path() { return null; }
|
141
|
/**
|
142
|
* Resets the form control. This means by default:
|
143
|
*
|
144
|
* * it is marked as `pristine`
|
145
|
* * it is marked as `untouched`
|
146
|
* * value is set to null
|
147
|
*
|
148
|
* For more information, see {\@link AbstractControl}.
|
149
|
* @param {?=} value
|
150
|
* @return {?}
|
151
|
*/
|
152
|
reset(value = undefined) {
|
153
|
if (this.control)
|
154
|
this.control.reset(value);
|
155
|
}
|
156
|
/**
|
157
|
* Returns true if the control with the given path has the error specified. Otherwise
|
158
|
* returns false.
|
159
|
*
|
160
|
* If no path is given, it checks for the error on the present control.
|
161
|
* @param {?} errorCode
|
162
|
* @param {?=} path
|
163
|
* @return {?}
|
164
|
*/
|
165
|
hasError(errorCode, path) {
|
166
|
return this.control ? this.control.hasError(errorCode, path) : false;
|
167
|
}
|
168
|
/**
|
169
|
* Returns error data if the control with the given path has the error specified. Otherwise
|
170
|
* returns null or undefined.
|
171
|
*
|
172
|
* If no path is given, it checks for the error on the present control.
|
173
|
* @param {?} errorCode
|
174
|
* @param {?=} path
|
175
|
* @return {?}
|
176
|
*/
|
177
|
getError(errorCode, path) {
|
178
|
return this.control ? this.control.getError(errorCode, path) : null;
|
179
|
}
|
180
|
}
|
181
|
|
182
|
/**
|
183
|
* @license
|
184
|
* Copyright Google Inc. All Rights Reserved.
|
185
|
*
|
186
|
* Use of this source code is governed by an MIT-style license that can be
|
187
|
* found in the LICENSE file at https://angular.io/license
|
188
|
*/
|
189
|
/**
|
190
|
* A directive that contains multiple {\@link NgControl}s.
|
191
|
*
|
192
|
* Only used by the forms module.
|
193
|
*
|
194
|
* \@stable
|
195
|
* @abstract
|
196
|
*/
|
197
|
class ControlContainer extends AbstractControlDirective {
|
198
|
/**
|
199
|
* Get the form to which this container belongs.
|
200
|
* @return {?}
|
201
|
*/
|
202
|
get formDirective() { return null; }
|
203
|
/**
|
204
|
* Get the path to this container.
|
205
|
* @return {?}
|
206
|
*/
|
207
|
get path() { return null; }
|
208
|
}
|
209
|
|
210
|
/**
|
211
|
* @license
|
212
|
* Copyright Google Inc. All Rights Reserved.
|
213
|
*
|
214
|
* Use of this source code is governed by an MIT-style license that can be
|
215
|
* found in the LICENSE file at https://angular.io/license
|
216
|
*/
|
217
|
/**
|
218
|
* @param {?} value
|
219
|
* @return {?}
|
220
|
*/
|
221
|
function isEmptyInputValue(value) {
|
222
|
// we don't check for string here so it also works with arrays
|
223
|
return value == null || value.length === 0;
|
224
|
}
|
225
|
/**
|
226
|
* Providers for validators to be used for {\@link FormControl}s in a form.
|
227
|
*
|
228
|
* Provide this using `multi: true` to add validators.
|
229
|
*
|
230
|
* \@stable
|
231
|
*/
|
232
|
const NG_VALIDATORS = new InjectionToken('NgValidators');
|
233
|
/**
|
234
|
* Providers for asynchronous validators to be used for {\@link FormControl}s
|
235
|
* in a form.
|
236
|
*
|
237
|
* Provide this using `multi: true` to add validators.
|
238
|
*
|
239
|
* See {\@link NG_VALIDATORS} for more details.
|
240
|
*
|
241
|
* \@stable
|
242
|
*/
|
243
|
const NG_ASYNC_VALIDATORS = new InjectionToken('NgAsyncValidators');
|
244
|
const EMAIL_REGEXP = /^(?=.{1,254}$)(?=.{1,64}@)[-!#$%&'*+/0-9=?A-Z^_`a-z{|}~]+(\.[-!#$%&'*+/0-9=?A-Z^_`a-z{|}~]+)*@[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?(\.[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?)*$/;
|
245
|
/**
|
246
|
* Provides a set of validators used by form controls.
|
247
|
*
|
248
|
* A validator is a function that processes a {\@link FormControl} or collection of
|
249
|
* controls and returns a map of errors. A null map means that validation has passed.
|
250
|
*
|
251
|
* ### Example
|
252
|
*
|
253
|
* ```typescript
|
254
|
* var loginControl = new FormControl("", Validators.required)
|
255
|
* ```
|
256
|
*
|
257
|
* \@stable
|
258
|
*/
|
259
|
class Validators {
|
260
|
/**
|
261
|
* Validator that requires controls to have a value greater than a number.
|
262
|
* @param {?} min
|
263
|
* @return {?}
|
264
|
*/
|
265
|
static min(min) {
|
266
|
return (control) => {
|
267
|
if (isEmptyInputValue(control.value) || isEmptyInputValue(min)) {
|
268
|
return null; // don't validate empty values to allow optional controls
|
269
|
}
|
270
|
const /** @type {?} */ value = parseFloat(control.value);
|
271
|
// Controls with NaN values after parsing should be treated as not having a
|
272
|
// minimum, per the HTML forms spec: https://www.w3.org/TR/html5/forms.html#attr-input-min
|
273
|
return !isNaN(value) && value < min ? { 'min': { 'min': min, 'actual': control.value } } : null;
|
274
|
};
|
275
|
}
|
276
|
/**
|
277
|
* Validator that requires controls to have a value less than a number.
|
278
|
* @param {?} max
|
279
|
* @return {?}
|
280
|
*/
|
281
|
static max(max) {
|
282
|
return (control) => {
|
283
|
if (isEmptyInputValue(control.value) || isEmptyInputValue(max)) {
|
284
|
return null; // don't validate empty values to allow optional controls
|
285
|
}
|
286
|
const /** @type {?} */ value = parseFloat(control.value);
|
287
|
// Controls with NaN values after parsing should be treated as not having a
|
288
|
// maximum, per the HTML forms spec: https://www.w3.org/TR/html5/forms.html#attr-input-max
|
289
|
return !isNaN(value) && value > max ? { 'max': { 'max': max, 'actual': control.value } } : null;
|
290
|
};
|
291
|
}
|
292
|
/**
|
293
|
* Validator that requires controls to have a non-empty value.
|
294
|
* @param {?} control
|
295
|
* @return {?}
|
296
|
*/
|
297
|
static required(control) {
|
298
|
return isEmptyInputValue(control.value) ? { 'required': true } : null;
|
299
|
}
|
300
|
/**
|
301
|
* Validator that requires control value to be true.
|
302
|
* @param {?} control
|
303
|
* @return {?}
|
304
|
*/
|
305
|
static requiredTrue(control) {
|
306
|
return control.value === true ? null : { 'required': true };
|
307
|
}
|
308
|
/**
|
309
|
* Validator that performs email validation.
|
310
|
* @param {?} control
|
311
|
* @return {?}
|
312
|
*/
|
313
|
static email(control) {
|
314
|
return EMAIL_REGEXP.test(control.value) ? null : { 'email': true };
|
315
|
}
|
316
|
/**
|
317
|
* Validator that requires controls to have a value of a minimum length.
|
318
|
* @param {?} minLength
|
319
|
* @return {?}
|
320
|
*/
|
321
|
static minLength(minLength) {
|
322
|
return (control) => {
|
323
|
if (isEmptyInputValue(control.value)) {
|
324
|
return null; // don't validate empty values to allow optional controls
|
325
|
}
|
326
|
const /** @type {?} */ length = control.value ? control.value.length : 0;
|
327
|
return length < minLength ?
|
328
|
{ 'minlength': { 'requiredLength': minLength, 'actualLength': length } } :
|
329
|
null;
|
330
|
};
|
331
|
}
|
332
|
/**
|
333
|
* Validator that requires controls to have a value of a maximum length.
|
334
|
* @param {?} maxLength
|
335
|
* @return {?}
|
336
|
*/
|
337
|
static maxLength(maxLength) {
|
338
|
return (control) => {
|
339
|
const /** @type {?} */ length = control.value ? control.value.length : 0;
|
340
|
return length > maxLength ?
|
341
|
{ 'maxlength': { 'requiredLength': maxLength, 'actualLength': length } } :
|
342
|
null;
|
343
|
};
|
344
|
}
|
345
|
/**
|
346
|
* Validator that requires a control to match a regex to its value.
|
347
|
* @param {?} pattern
|
348
|
* @return {?}
|
349
|
*/
|
350
|
static pattern(pattern) {
|
351
|
if (!pattern)
|
352
|
return Validators.nullValidator;
|
353
|
let /** @type {?} */ regex;
|
354
|
let /** @type {?} */ regexStr;
|
355
|
if (typeof pattern === 'string') {
|
356
|
regexStr = `^${pattern}$`;
|
357
|
regex = new RegExp(regexStr);
|
358
|
}
|
359
|
else {
|
360
|
regexStr = pattern.toString();
|
361
|
regex = pattern;
|
362
|
}
|
363
|
return (control) => {
|
364
|
if (isEmptyInputValue(control.value)) {
|
365
|
return null; // don't validate empty values to allow optional controls
|
366
|
}
|
367
|
const /** @type {?} */ value = control.value;
|
368
|
return regex.test(value) ? null :
|
369
|
{ 'pattern': { 'requiredPattern': regexStr, 'actualValue': value } };
|
370
|
};
|
371
|
}
|
372
|
/**
|
373
|
* No-op validator.
|
374
|
* @param {?} c
|
375
|
* @return {?}
|
376
|
*/
|
377
|
static nullValidator(c) { return null; }
|
378
|
/**
|
379
|
* @param {?} validators
|
380
|
* @return {?}
|
381
|
*/
|
382
|
static compose(validators) {
|
383
|
if (!validators)
|
384
|
return null;
|
385
|
const /** @type {?} */ presentValidators = (validators.filter(isPresent));
|
386
|
if (presentValidators.length == 0)
|
387
|
return null;
|
388
|
return function (control) {
|
389
|
return _mergeErrors(_executeValidators(control, presentValidators));
|
390
|
};
|
391
|
}
|
392
|
/**
|
393
|
* @param {?} validators
|
394
|
* @return {?}
|
395
|
*/
|
396
|
static composeAsync(validators) {
|
397
|
if (!validators)
|
398
|
return null;
|
399
|
const /** @type {?} */ presentValidators = (validators.filter(isPresent));
|
400
|
if (presentValidators.length == 0)
|
401
|
return null;
|
402
|
return function (control) {
|
403
|
const /** @type {?} */ observables = _executeAsyncValidators(control, presentValidators).map(toObservable);
|
404
|
return map.call(forkJoin(observables), _mergeErrors);
|
405
|
};
|
406
|
}
|
407
|
}
|
408
|
/**
|
409
|
* @param {?} o
|
410
|
* @return {?}
|
411
|
*/
|
412
|
function isPresent(o) {
|
413
|
return o != null;
|
414
|
}
|
415
|
/**
|
416
|
* @param {?} r
|
417
|
* @return {?}
|
418
|
*/
|
419
|
function toObservable(r) {
|
420
|
const /** @type {?} */ obs = ɵisPromise(r) ? fromPromise(r) : r;
|
421
|
if (!(ɵisObservable(obs))) {
|
422
|
throw new Error(`Expected validator to return Promise or Observable.`);
|
423
|
}
|
424
|
return obs;
|
425
|
}
|
426
|
/**
|
427
|
* @param {?} control
|
428
|
* @param {?} validators
|
429
|
* @return {?}
|
430
|
*/
|
431
|
function _executeValidators(control, validators) {
|
432
|
return validators.map(v => v(control));
|
433
|
}
|
434
|
/**
|
435
|
* @param {?} control
|
436
|
* @param {?} validators
|
437
|
* @return {?}
|
438
|
*/
|
439
|
function _executeAsyncValidators(control, validators) {
|
440
|
return validators.map(v => v(control));
|
441
|
}
|
442
|
/**
|
443
|
* @param {?} arrayOfErrors
|
444
|
* @return {?}
|
445
|
*/
|
446
|
function _mergeErrors(arrayOfErrors) {
|
447
|
const /** @type {?} */ res = arrayOfErrors.reduce((res, errors) => {
|
448
|
return errors != null ? Object.assign({}, /** @type {?} */ ((res)), errors) : ((res));
|
449
|
}, {});
|
450
|
return Object.keys(res).length === 0 ? null : res;
|
451
|
}
|
452
|
|
453
|
/**
|
454
|
* @license
|
455
|
* Copyright Google Inc. All Rights Reserved.
|
456
|
*
|
457
|
* Use of this source code is governed by an MIT-style license that can be
|
458
|
* found in the LICENSE file at https://angular.io/license
|
459
|
*/
|
460
|
/**
|
461
|
* Used to provide a {\@link ControlValueAccessor} for form controls.
|
462
|
*
|
463
|
* See {\@link DefaultValueAccessor} for how to implement one.
|
464
|
* \@stable
|
465
|
*/
|
466
|
const NG_VALUE_ACCESSOR = new InjectionToken('NgValueAccessor');
|
467
|
|
468
|
/**
|
469
|
* @license
|
470
|
* Copyright Google Inc. All Rights Reserved.
|
471
|
*
|
472
|
* Use of this source code is governed by an MIT-style license that can be
|
473
|
* found in the LICENSE file at https://angular.io/license
|
474
|
*/
|
475
|
const CHECKBOX_VALUE_ACCESSOR = {
|
476
|
provide: NG_VALUE_ACCESSOR,
|
477
|
useExisting: forwardRef(() => CheckboxControlValueAccessor),
|
478
|
multi: true,
|
479
|
};
|
480
|
/**
|
481
|
* The accessor for writing a value and listening to changes on a checkbox input element.
|
482
|
*
|
483
|
* ### Example
|
484
|
* ```
|
485
|
* <input type="checkbox" name="rememberLogin" ngModel>
|
486
|
* ```
|
487
|
*
|
488
|
* \@stable
|
489
|
*/
|
490
|
class CheckboxControlValueAccessor {
|
491
|
/**
|
492
|
* @param {?} _renderer
|
493
|
* @param {?} _elementRef
|
494
|
*/
|
495
|
constructor(_renderer, _elementRef) {
|
496
|
this._renderer = _renderer;
|
497
|
this._elementRef = _elementRef;
|
498
|
this.onChange = (_) => { };
|
499
|
this.onTouched = () => { };
|
500
|
}
|
501
|
/**
|
502
|
* @param {?} value
|
503
|
* @return {?}
|
504
|
*/
|
505
|
writeValue(value) {
|
506
|
this._renderer.setProperty(this._elementRef.nativeElement, 'checked', value);
|
507
|
}
|
508
|
/**
|
509
|
* @param {?} fn
|
510
|
* @return {?}
|
511
|
*/
|
512
|
registerOnChange(fn) { this.onChange = fn; }
|
513
|
/**
|
514
|
* @param {?} fn
|
515
|
* @return {?}
|
516
|
*/
|
517
|
registerOnTouched(fn) { this.onTouched = fn; }
|
518
|
/**
|
519
|
* @param {?} isDisabled
|
520
|
* @return {?}
|
521
|
*/
|
522
|
setDisabledState(isDisabled) {
|
523
|
this._renderer.setProperty(this._elementRef.nativeElement, 'disabled', isDisabled);
|
524
|
}
|
525
|
}
|
526
|
CheckboxControlValueAccessor.decorators = [
|
527
|
{ type: Directive, args: [{
|
528
|
selector: 'input[type=checkbox][formControlName],input[type=checkbox][formControl],input[type=checkbox][ngModel]',
|
529
|
host: { '(change)': 'onChange($event.target.checked)', '(blur)': 'onTouched()' },
|
530
|
providers: [CHECKBOX_VALUE_ACCESSOR]
|
531
|
},] },
|
532
|
];
|
533
|
/**
|
534
|
* @nocollapse
|
535
|
*/
|
536
|
CheckboxControlValueAccessor.ctorParameters = () => [
|
537
|
{ type: Renderer2, },
|
538
|
{ type: ElementRef, },
|
539
|
];
|
540
|
|
541
|
/**
|
542
|
* @license
|
543
|
* Copyright Google Inc. All Rights Reserved.
|
544
|
*
|
545
|
* Use of this source code is governed by an MIT-style license that can be
|
546
|
* found in the LICENSE file at https://angular.io/license
|
547
|
*/
|
548
|
const DEFAULT_VALUE_ACCESSOR = {
|
549
|
provide: NG_VALUE_ACCESSOR,
|
550
|
useExisting: forwardRef(() => DefaultValueAccessor),
|
551
|
multi: true
|
552
|
};
|
553
|
/**
|
554
|
* We must check whether the agent is Android because composition events
|
555
|
* behave differently between iOS and Android.
|
556
|
* @return {?}
|
557
|
*/
|
558
|
function _isAndroid() {
|
559
|
const /** @type {?} */ userAgent = ɵgetDOM() ? ɵgetDOM().getUserAgent() : '';
|
560
|
return /android (\d+)/.test(userAgent.toLowerCase());
|
561
|
}
|
562
|
/**
|
563
|
* Turn this mode on if you want form directives to buffer IME input until compositionend
|
564
|
* \@experimental
|
565
|
*/
|
566
|
const COMPOSITION_BUFFER_MODE = new InjectionToken('CompositionEventMode');
|
567
|
/**
|
568
|
* The default accessor for writing a value and listening to changes that is used by the
|
569
|
* {\@link NgModel}, {\@link FormControlDirective}, and {\@link FormControlName} directives.
|
570
|
*
|
571
|
* ### Example
|
572
|
* ```
|
573
|
* <input type="text" name="searchQuery" ngModel>
|
574
|
* ```
|
575
|
*
|
576
|
* \@stable
|
577
|
*/
|
578
|
class DefaultValueAccessor {
|
579
|
/**
|
580
|
* @param {?} _renderer
|
581
|
* @param {?} _elementRef
|
582
|
* @param {?} _compositionMode
|
583
|
*/
|
584
|
constructor(_renderer, _elementRef, _compositionMode) {
|
585
|
this._renderer = _renderer;
|
586
|
this._elementRef = _elementRef;
|
587
|
this._compositionMode = _compositionMode;
|
588
|
this.onChange = (_) => { };
|
589
|
this.onTouched = () => { };
|
590
|
/**
|
591
|
* Whether the user is creating a composition string (IME events).
|
592
|
*/
|
593
|
this._composing = false;
|
594
|
if (this._compositionMode == null) {
|
595
|
this._compositionMode = !_isAndroid();
|
596
|
}
|
597
|
}
|
598
|
/**
|
599
|
* @param {?} value
|
600
|
* @return {?}
|
601
|
*/
|
602
|
writeValue(value) {
|
603
|
const /** @type {?} */ normalizedValue = value == null ? '' : value;
|
604
|
this._renderer.setProperty(this._elementRef.nativeElement, 'value', normalizedValue);
|
605
|
}
|
606
|
/**
|
607
|
* @param {?} fn
|
608
|
* @return {?}
|
609
|
*/
|
610
|
registerOnChange(fn) { this.onChange = fn; }
|
611
|
/**
|
612
|
* @param {?} fn
|
613
|
* @return {?}
|
614
|
*/
|
615
|
registerOnTouched(fn) { this.onTouched = fn; }
|
616
|
/**
|
617
|
* @param {?} isDisabled
|
618
|
* @return {?}
|
619
|
*/
|
620
|
setDisabledState(isDisabled) {
|
621
|
this._renderer.setProperty(this._elementRef.nativeElement, 'disabled', isDisabled);
|
622
|
}
|
623
|
/**
|
624
|
* \@internal
|
625
|
* @param {?} value
|
626
|
* @return {?}
|
627
|
*/
|
628
|
_handleInput(value) {
|
629
|
if (!this._compositionMode || (this._compositionMode && !this._composing)) {
|
630
|
this.onChange(value);
|
631
|
}
|
632
|
}
|
633
|
/**
|
634
|
* \@internal
|
635
|
* @return {?}
|
636
|
*/
|
637
|
_compositionStart() { this._composing = true; }
|
638
|
/**
|
639
|
* \@internal
|
640
|
* @param {?} value
|
641
|
* @return {?}
|
642
|
*/
|
643
|
_compositionEnd(value) {
|
644
|
this._composing = false;
|
645
|
this._compositionMode && this.onChange(value);
|
646
|
}
|
647
|
}
|
648
|
DefaultValueAccessor.decorators = [
|
649
|
{ type: Directive, args: [{
|
650
|
selector: 'input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]',
|
651
|
// TODO: vsavkin replace the above selector with the one below it once
|
652
|
// https://github.com/angular/angular/issues/3011 is implemented
|
653
|
// selector: '[ngModel],[formControl],[formControlName]',
|
654
|
host: {
|
655
|
'(input)': '_handleInput($event.target.value)',
|
656
|
'(blur)': 'onTouched()',
|
657
|
'(compositionstart)': '_compositionStart()',
|
658
|
'(compositionend)': '_compositionEnd($event.target.value)'
|
659
|
},
|
660
|
providers: [DEFAULT_VALUE_ACCESSOR]
|
661
|
},] },
|
662
|
];
|
663
|
/**
|
664
|
* @nocollapse
|
665
|
*/
|
666
|
DefaultValueAccessor.ctorParameters = () => [
|
667
|
{ type: Renderer2, },
|
668
|
{ type: ElementRef, },
|
669
|
{ type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [COMPOSITION_BUFFER_MODE,] },] },
|
670
|
];
|
671
|
|
672
|
/**
|
673
|
* @license
|
674
|
* Copyright Google Inc. All Rights Reserved.
|
675
|
*
|
676
|
* Use of this source code is governed by an MIT-style license that can be
|
677
|
* found in the LICENSE file at https://angular.io/license
|
678
|
*/
|
679
|
/**
|
680
|
* @param {?} validator
|
681
|
* @return {?}
|
682
|
*/
|
683
|
function normalizeValidator(validator) {
|
684
|
if (((validator)).validate) {
|
685
|
return (c) => ((validator)).validate(c);
|
686
|
}
|
687
|
else {
|
688
|
return (validator);
|
689
|
}
|
690
|
}
|
691
|
/**
|
692
|
* @param {?} validator
|
693
|
* @return {?}
|
694
|
*/
|
695
|
function normalizeAsyncValidator(validator) {
|
696
|
if (((validator)).validate) {
|
697
|
return (c) => ((validator)).validate(c);
|
698
|
}
|
699
|
else {
|
700
|
return (validator);
|
701
|
}
|
702
|
}
|
703
|
|
704
|
/**
|
705
|
* @license
|
706
|
* Copyright Google Inc. All Rights Reserved.
|
707
|
*
|
708
|
* Use of this source code is governed by an MIT-style license that can be
|
709
|
* found in the LICENSE file at https://angular.io/license
|
710
|
*/
|
711
|
const NUMBER_VALUE_ACCESSOR = {
|
712
|
provide: NG_VALUE_ACCESSOR,
|
713
|
useExisting: forwardRef(() => NumberValueAccessor),
|
714
|
multi: true
|
715
|
};
|
716
|
/**
|
717
|
* The accessor for writing a number value and listening to changes that is used by the
|
718
|
* {\@link NgModel}, {\@link FormControlDirective}, and {\@link FormControlName} directives.
|
719
|
*
|
720
|
* ### Example
|
721
|
* ```
|
722
|
* <input type="number" [(ngModel)]="age">
|
723
|
* ```
|
724
|
*/
|
725
|
class NumberValueAccessor {
|
726
|
/**
|
727
|
* @param {?} _renderer
|
728
|
* @param {?} _elementRef
|
729
|
*/
|
730
|
constructor(_renderer, _elementRef) {
|
731
|
this._renderer = _renderer;
|
732
|
this._elementRef = _elementRef;
|
733
|
this.onChange = (_) => { };
|
734
|
this.onTouched = () => { };
|
735
|
}
|
736
|
/**
|
737
|
* @param {?} value
|
738
|
* @return {?}
|
739
|
*/
|
740
|
writeValue(value) {
|
741
|
// The value needs to be normalized for IE9, otherwise it is set to 'null' when null
|
742
|
const /** @type {?} */ normalizedValue = value == null ? '' : value;
|
743
|
this._renderer.setProperty(this._elementRef.nativeElement, 'value', normalizedValue);
|
744
|
}
|
745
|
/**
|
746
|
* @param {?} fn
|
747
|
* @return {?}
|
748
|
*/
|
749
|
registerOnChange(fn) {
|
750
|
this.onChange = (value) => { fn(value == '' ? null : parseFloat(value)); };
|
751
|
}
|
752
|
/**
|
753
|
* @param {?} fn
|
754
|
* @return {?}
|
755
|
*/
|
756
|
registerOnTouched(fn) { this.onTouched = fn; }
|
757
|
/**
|
758
|
* @param {?} isDisabled
|
759
|
* @return {?}
|
760
|
*/
|
761
|
setDisabledState(isDisabled) {
|
762
|
this._renderer.setProperty(this._elementRef.nativeElement, 'disabled', isDisabled);
|
763
|
}
|
764
|
}
|
765
|
NumberValueAccessor.decorators = [
|
766
|
{ type: Directive, args: [{
|
767
|
selector: 'input[type=number][formControlName],input[type=number][formControl],input[type=number][ngModel]',
|
768
|
host: {
|
769
|
'(change)': 'onChange($event.target.value)',
|
770
|
'(input)': 'onChange($event.target.value)',
|
771
|
'(blur)': 'onTouched()'
|
772
|
},
|
773
|
providers: [NUMBER_VALUE_ACCESSOR]
|
774
|
},] },
|
775
|
];
|
776
|
/**
|
777
|
* @nocollapse
|
778
|
*/
|
779
|
NumberValueAccessor.ctorParameters = () => [
|
780
|
{ type: Renderer2, },
|
781
|
{ type: ElementRef, },
|
782
|
];
|
783
|
|
784
|
/**
|
785
|
* @license
|
786
|
* Copyright Google Inc. All Rights Reserved.
|
787
|
*
|
788
|
* Use of this source code is governed by an MIT-style license that can be
|
789
|
* found in the LICENSE file at https://angular.io/license
|
790
|
*/
|
791
|
/**
|
792
|
* @return {?}
|
793
|
*/
|
794
|
function unimplemented() {
|
795
|
throw new Error('unimplemented');
|
796
|
}
|
797
|
/**
|
798
|
* A base class that all control directive extend.
|
799
|
* It binds a {\@link FormControl} object to a DOM element.
|
800
|
*
|
801
|
* Used internally by Angular forms.
|
802
|
*
|
803
|
* \@stable
|
804
|
* @abstract
|
805
|
*/
|
806
|
class NgControl extends AbstractControlDirective {
|
807
|
constructor() {
|
808
|
super(...arguments);
|
809
|
/**
|
810
|
* \@internal
|
811
|
*/
|
812
|
this._parent = null;
|
813
|
this.name = null;
|
814
|
this.valueAccessor = null;
|
815
|
/**
|
816
|
* \@internal
|
817
|
*/
|
818
|
this._rawValidators = [];
|
819
|
/**
|
820
|
* \@internal
|
821
|
*/
|
822
|
this._rawAsyncValidators = [];
|
823
|
}
|
824
|
/**
|
825
|
* @return {?}
|
826
|
*/
|
827
|
get validator() { return (unimplemented()); }
|
828
|
/**
|
829
|
* @return {?}
|
830
|
*/
|
831
|
get asyncValidator() { return (unimplemented()); }
|
832
|
/**
|
833
|
* @abstract
|
834
|
* @param {?} newValue
|
835
|
* @return {?}
|
836
|
*/
|
837
|
viewToModelUpdate(newValue) { }
|
838
|
}
|
839
|
|
840
|
/**
|
841
|
* @license
|
842
|
* Copyright Google Inc. All Rights Reserved.
|
843
|
*
|
844
|
* Use of this source code is governed by an MIT-style license that can be
|
845
|
* found in the LICENSE file at https://angular.io/license
|
846
|
*/
|
847
|
const RADIO_VALUE_ACCESSOR = {
|
848
|
provide: NG_VALUE_ACCESSOR,
|
849
|
useExisting: forwardRef(() => RadioControlValueAccessor),
|
850
|
multi: true
|
851
|
};
|
852
|
/**
|
853
|
* Internal class used by Angular to uncheck radio buttons with the matching name.
|
854
|
*/
|
855
|
class RadioControlRegistry {
|
856
|
constructor() {
|
857
|
this._accessors = [];
|
858
|
}
|
859
|
/**
|
860
|
* @param {?} control
|
861
|
* @param {?} accessor
|
862
|
* @return {?}
|
863
|
*/
|
864
|
add(control, accessor) {
|
865
|
this._accessors.push([control, accessor]);
|
866
|
}
|
867
|
/**
|
868
|
* @param {?} accessor
|
869
|
* @return {?}
|
870
|
*/
|
871
|
remove(accessor) {
|
872
|
for (let /** @type {?} */ i = this._accessors.length - 1; i >= 0; --i) {
|
873
|
if (this._accessors[i][1] === accessor) {
|
874
|
this._accessors.splice(i, 1);
|
875
|
return;
|
876
|
}
|
877
|
}
|
878
|
}
|
879
|
/**
|
880
|
* @param {?} accessor
|
881
|
* @return {?}
|
882
|
*/
|
883
|
select(accessor) {
|
884
|
this._accessors.forEach((c) => {
|
885
|
if (this._isSameGroup(c, accessor) && c[1] !== accessor) {
|
886
|
c[1].fireUncheck(accessor.value);
|
887
|
}
|
888
|
});
|
889
|
}
|
890
|
/**
|
891
|
* @param {?} controlPair
|
892
|
* @param {?} accessor
|
893
|
* @return {?}
|
894
|
*/
|
895
|
_isSameGroup(controlPair, accessor) {
|
896
|
if (!controlPair[0].control)
|
897
|
return false;
|
898
|
return controlPair[0]._parent === accessor._control._parent &&
|
899
|
controlPair[1].name === accessor.name;
|
900
|
}
|
901
|
}
|
902
|
RadioControlRegistry.decorators = [
|
903
|
{ type: Injectable },
|
904
|
];
|
905
|
/**
|
906
|
* @nocollapse
|
907
|
*/
|
908
|
RadioControlRegistry.ctorParameters = () => [];
|
909
|
/**
|
910
|
* \@whatItDoes Writes radio control values and listens to radio control changes.
|
911
|
*
|
912
|
* Used by {\@link NgModel}, {\@link FormControlDirective}, and {\@link FormControlName}
|
913
|
* to keep the view synced with the {\@link FormControl} model.
|
914
|
*
|
915
|
* \@howToUse
|
916
|
*
|
917
|
* If you have imported the {\@link FormsModule} or the {\@link ReactiveFormsModule}, this
|
918
|
* value accessor will be active on any radio control that has a form directive. You do
|
919
|
* **not** need to add a special selector to activate it.
|
920
|
*
|
921
|
* ### How to use radio buttons with form directives
|
922
|
*
|
923
|
* To use radio buttons in a template-driven form, you'll want to ensure that radio buttons
|
924
|
* in the same group have the same `name` attribute. Radio buttons with different `name`
|
925
|
* attributes do not affect each other.
|
926
|
*
|
927
|
* {\@example forms/ts/radioButtons/radio_button_example.ts region='TemplateDriven'}
|
928
|
*
|
929
|
* When using radio buttons in a reactive form, radio buttons in the same group should have the
|
930
|
* same `formControlName`. You can also add a `name` attribute, but it's optional.
|
931
|
*
|
932
|
* {\@example forms/ts/reactiveRadioButtons/reactive_radio_button_example.ts region='Reactive'}
|
933
|
*
|
934
|
* * **npm package**: `\@angular/forms`
|
935
|
*
|
936
|
* \@stable
|
937
|
*/
|
938
|
class RadioControlValueAccessor {
|
939
|
/**
|
940
|
* @param {?} _renderer
|
941
|
* @param {?} _elementRef
|
942
|
* @param {?} _registry
|
943
|
* @param {?} _injector
|
944
|
*/
|
945
|
constructor(_renderer, _elementRef, _registry, _injector) {
|
946
|
this._renderer = _renderer;
|
947
|
this._elementRef = _elementRef;
|
948
|
this._registry = _registry;
|
949
|
this._injector = _injector;
|
950
|
this.onChange = () => { };
|
951
|
this.onTouched = () => { };
|
952
|
}
|
953
|
/**
|
954
|
* @return {?}
|
955
|
*/
|
956
|
ngOnInit() {
|
957
|
this._control = this._injector.get(NgControl);
|
958
|
this._checkName();
|
959
|
this._registry.add(this._control, this);
|
960
|
}
|
961
|
/**
|
962
|
* @return {?}
|
963
|
*/
|
964
|
ngOnDestroy() { this._registry.remove(this); }
|
965
|
/**
|
966
|
* @param {?} value
|
967
|
* @return {?}
|
968
|
*/
|
969
|
writeValue(value) {
|
970
|
this._state = value === this.value;
|
971
|
this._renderer.setProperty(this._elementRef.nativeElement, 'checked', this._state);
|
972
|
}
|
973
|
/**
|
974
|
* @param {?} fn
|
975
|
* @return {?}
|
976
|
*/
|
977
|
registerOnChange(fn) {
|
978
|
this._fn = fn;
|
979
|
this.onChange = () => {
|
980
|
fn(this.value);
|
981
|
this._registry.select(this);
|
982
|
};
|
983
|
}
|
984
|
/**
|
985
|
* @param {?} value
|
986
|
* @return {?}
|
987
|
*/
|
988
|
fireUncheck(value) { this.writeValue(value); }
|
989
|
/**
|
990
|
* @param {?} fn
|
991
|
* @return {?}
|
992
|
*/
|
993
|
registerOnTouched(fn) { this.onTouched = fn; }
|
994
|
/**
|
995
|
* @param {?} isDisabled
|
996
|
* @return {?}
|
997
|
*/
|
998
|
setDisabledState(isDisabled) {
|
999
|
this._renderer.setProperty(this._elementRef.nativeElement, 'disabled', isDisabled);
|
1000
|
}
|
1001
|
/**
|
1002
|
* @return {?}
|
1003
|
*/
|
1004
|
_checkName() {
|
1005
|
if (this.name && this.formControlName && this.name !== this.formControlName) {
|
1006
|
this._throwNameError();
|
1007
|
}
|
1008
|
if (!this.name && this.formControlName)
|
1009
|
this.name = this.formControlName;
|
1010
|
}
|
1011
|
/**
|
1012
|
* @return {?}
|
1013
|
*/
|
1014
|
_throwNameError() {
|
1015
|
throw new Error(`
|
1016
|
If you define both a name and a formControlName attribute on your radio button, their values
|
1017
|
must match. Ex: <input type="radio" formControlName="food" name="food">
|
1018
|
`);
|
1019
|
}
|
1020
|
}
|
1021
|
RadioControlValueAccessor.decorators = [
|
1022
|
{ type: Directive, args: [{
|
1023
|
selector: 'input[type=radio][formControlName],input[type=radio][formControl],input[type=radio][ngModel]',
|
1024
|
host: { '(change)': 'onChange()', '(blur)': 'onTouched()' },
|
1025
|
providers: [RADIO_VALUE_ACCESSOR]
|
1026
|
},] },
|
1027
|
];
|
1028
|
/**
|
1029
|
* @nocollapse
|
1030
|
*/
|
1031
|
RadioControlValueAccessor.ctorParameters = () => [
|
1032
|
{ type: Renderer2, },
|
1033
|
{ type: ElementRef, },
|
1034
|
{ type: RadioControlRegistry, },
|
1035
|
{ type: Injector, },
|
1036
|
];
|
1037
|
RadioControlValueAccessor.propDecorators = {
|
1038
|
'name': [{ type: Input },],
|
1039
|
'formControlName': [{ type: Input },],
|
1040
|
'value': [{ type: Input },],
|
1041
|
};
|
1042
|
|
1043
|
/**
|
1044
|
* @license
|
1045
|
* Copyright Google Inc. All Rights Reserved.
|
1046
|
*
|
1047
|
* Use of this source code is governed by an MIT-style license that can be
|
1048
|
* found in the LICENSE file at https://angular.io/license
|
1049
|
*/
|
1050
|
const RANGE_VALUE_ACCESSOR = {
|
1051
|
provide: NG_VALUE_ACCESSOR,
|
1052
|
useExisting: forwardRef(() => RangeValueAccessor),
|
1053
|
multi: true
|
1054
|
};
|
1055
|
/**
|
1056
|
* The accessor for writing a range value and listening to changes that is used by the
|
1057
|
* {\@link NgModel}, {\@link FormControlDirective}, and {\@link FormControlName} directives.
|
1058
|
*
|
1059
|
* ### Example
|
1060
|
* ```
|
1061
|
* <input type="range" [(ngModel)]="age" >
|
1062
|
* ```
|
1063
|
*/
|
1064
|
class RangeValueAccessor {
|
1065
|
/**
|
1066
|
* @param {?} _renderer
|
1067
|
* @param {?} _elementRef
|
1068
|
*/
|
1069
|
constructor(_renderer, _elementRef) {
|
1070
|
this._renderer = _renderer;
|
1071
|
this._elementRef = _elementRef;
|
1072
|
this.onChange = (_) => { };
|
1073
|
this.onTouched = () => { };
|
1074
|
}
|
1075
|
/**
|
1076
|
* @param {?} value
|
1077
|
* @return {?}
|
1078
|
*/
|
1079
|
writeValue(value) {
|
1080
|
this._renderer.setProperty(this._elementRef.nativeElement, 'value', parseFloat(value));
|
1081
|
}
|
1082
|
/**
|
1083
|
* @param {?} fn
|
1084
|
* @return {?}
|
1085
|
*/
|
1086
|
registerOnChange(fn) {
|
1087
|
this.onChange = (value) => { fn(value == '' ? null : parseFloat(value)); };
|
1088
|
}
|
1089
|
/**
|
1090
|
* @param {?} fn
|
1091
|
* @return {?}
|
1092
|
*/
|
1093
|
registerOnTouched(fn) { this.onTouched = fn; }
|
1094
|
/**
|
1095
|
* @param {?} isDisabled
|
1096
|
* @return {?}
|
1097
|
*/
|
1098
|
setDisabledState(isDisabled) {
|
1099
|
this._renderer.setProperty(this._elementRef.nativeElement, 'disabled', isDisabled);
|
1100
|
}
|
1101
|
}
|
1102
|
RangeValueAccessor.decorators = [
|
1103
|
{ type: Directive, args: [{
|
1104
|
selector: 'input[type=range][formControlName],input[type=range][formControl],input[type=range][ngModel]',
|
1105
|
host: {
|
1106
|
'(change)': 'onChange($event.target.value)',
|
1107
|
'(input)': 'onChange($event.target.value)',
|
1108
|
'(blur)': 'onTouched()'
|
1109
|
},
|
1110
|
providers: [RANGE_VALUE_ACCESSOR]
|
1111
|
},] },
|
1112
|
];
|
1113
|
/**
|
1114
|
* @nocollapse
|
1115
|
*/
|
1116
|
RangeValueAccessor.ctorParameters = () => [
|
1117
|
{ type: Renderer2, },
|
1118
|
{ type: ElementRef, },
|
1119
|
];
|
1120
|
|
1121
|
/**
|
1122
|
* @license
|
1123
|
* Copyright Google Inc. All Rights Reserved.
|
1124
|
*
|
1125
|
* Use of this source code is governed by an MIT-style license that can be
|
1126
|
* found in the LICENSE file at https://angular.io/license
|
1127
|
*/
|
1128
|
const SELECT_VALUE_ACCESSOR = {
|
1129
|
provide: NG_VALUE_ACCESSOR,
|
1130
|
useExisting: forwardRef(() => SelectControlValueAccessor),
|
1131
|
multi: true
|
1132
|
};
|
1133
|
/**
|
1134
|
* @param {?} id
|
1135
|
* @param {?} value
|
1136
|
* @return {?}
|
1137
|
*/
|
1138
|
function _buildValueString(id, value) {
|
1139
|
if (id == null)
|
1140
|
return `${value}`;
|
1141
|
if (value && typeof value === 'object')
|
1142
|
value = 'Object';
|
1143
|
return `${id}: ${value}`.slice(0, 50);
|
1144
|
}
|
1145
|
/**
|
1146
|
* @param {?} valueString
|
1147
|
* @return {?}
|
1148
|
*/
|
1149
|
function _extractId(valueString) {
|
1150
|
return valueString.split(':')[0];
|
1151
|
}
|
1152
|
/**
|
1153
|
* \@whatItDoes Writes values and listens to changes on a select element.
|
1154
|
*
|
1155
|
* Used by {\@link NgModel}, {\@link FormControlDirective}, and {\@link FormControlName}
|
1156
|
* to keep the view synced with the {\@link FormControl} model.
|
1157
|
*
|
1158
|
* \@howToUse
|
1159
|
*
|
1160
|
* If you have imported the {\@link FormsModule} or the {\@link ReactiveFormsModule}, this
|
1161
|
* value accessor will be active on any select control that has a form directive. You do
|
1162
|
* **not** need to add a special selector to activate it.
|
1163
|
*
|
1164
|
* ### How to use select controls with form directives
|
1165
|
*
|
1166
|
* To use a select in a template-driven form, simply add an `ngModel` and a `name`
|
1167
|
* attribute to the main `<select>` tag.
|
1168
|
*
|
1169
|
* If your option values are simple strings, you can bind to the normal `value` property
|
1170
|
* on the option. If your option values happen to be objects (and you'd like to save the
|
1171
|
* selection in your form as an object), use `ngValue` instead:
|
1172
|
*
|
1173
|
* {\@example forms/ts/selectControl/select_control_example.ts region='Component'}
|
1174
|
*
|
1175
|
* In reactive forms, you'll also want to add your form directive (`formControlName` or
|
1176
|
* `formControl`) on the main `<select>` tag. Like in the former example, you have the
|
1177
|
* choice of binding to the `value` or `ngValue` property on the select's options.
|
1178
|
*
|
1179
|
* {\@example forms/ts/reactiveSelectControl/reactive_select_control_example.ts region='Component'}
|
1180
|
*
|
1181
|
* ### Caveat: Option selection
|
1182
|
*
|
1183
|
* Angular uses object identity to select option. It's possible for the identities of items
|
1184
|
* to change while the data does not. This can happen, for example, if the items are produced
|
1185
|
* from an RPC to the server, and that RPC is re-run. Even if the data hasn't changed, the
|
1186
|
* second response will produce objects with different identities.
|
1187
|
*
|
1188
|
* To customize the default option comparison algorithm, `<select>` supports `compareWith` input.
|
1189
|
* `compareWith` takes a **function** which has two arguments: `option1` and `option2`.
|
1190
|
* If `compareWith` is given, Angular selects option by the return value of the function.
|
1191
|
*
|
1192
|
* #### Syntax
|
1193
|
*
|
1194
|
* ```
|
1195
|
* <select [compareWith]="compareFn" [(ngModel)]="selectedCountries">
|
1196
|
* <option *ngFor="let country of countries" [ngValue]="country">
|
1197
|
* {{country.name}}
|
1198
|
* </option>
|
1199
|
* </select>
|
1200
|
*
|
1201
|
* compareFn(c1: Country, c2: Country): boolean {
|
1202
|
* return c1 && c2 ? c1.id === c2.id : c1 === c2;
|
1203
|
* }
|
1204
|
* ```
|
1205
|
*
|
1206
|
* Note: We listen to the 'change' event because 'input' events aren't fired
|
1207
|
* for selects in Firefox and IE:
|
1208
|
* https://bugzilla.mozilla.org/show_bug.cgi?id=1024350
|
1209
|
* https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/4660045/
|
1210
|
*
|
1211
|
* * **npm package**: `\@angular/forms`
|
1212
|
*
|
1213
|
* \@stable
|
1214
|
*/
|
1215
|
class SelectControlValueAccessor {
|
1216
|
/**
|
1217
|
* @param {?} _renderer
|
1218
|
* @param {?} _elementRef
|
1219
|
*/
|
1220
|
constructor(_renderer, _elementRef) {
|
1221
|
this._renderer = _renderer;
|
1222
|
this._elementRef = _elementRef;
|
1223
|
/**
|
1224
|
* \@internal
|
1225
|
*/
|
1226
|
this._optionMap = new Map();
|
1227
|
/**
|
1228
|
* \@internal
|
1229
|
*/
|
1230
|
this._idCounter = 0;
|
1231
|
this.onChange = (_) => { };
|
1232
|
this.onTouched = () => { };
|
1233
|
this._compareWith = ɵlooseIdentical;
|
1234
|
}
|
1235
|
/**
|
1236
|
* @param {?} fn
|
1237
|
* @return {?}
|
1238
|
*/
|
1239
|
set compareWith(fn) {
|
1240
|
if (typeof fn !== 'function') {
|
1241
|
throw new Error(`compareWith must be a function, but received ${JSON.stringify(fn)}`);
|
1242
|
}
|
1243
|
this._compareWith = fn;
|
1244
|
}
|
1245
|
/**
|
1246
|
* @param {?} value
|
1247
|
* @return {?}
|
1248
|
*/
|
1249
|
writeValue(value) {
|
1250
|
this.value = value;
|
1251
|
const /** @type {?} */ id = this._getOptionId(value);
|
1252
|
if (id == null) {
|
1253
|
this._renderer.setProperty(this._elementRef.nativeElement, 'selectedIndex', -1);
|
1254
|
}
|
1255
|
const /** @type {?} */ valueString = _buildValueString(id, value);
|
1256
|
this._renderer.setProperty(this._elementRef.nativeElement, 'value', valueString);
|
1257
|
}
|
1258
|
/**
|
1259
|
* @param {?} fn
|
1260
|
* @return {?}
|
1261
|
*/
|
1262
|
registerOnChange(fn) {
|
1263
|
this.onChange = (valueString) => {
|
1264
|
this.value = this._getOptionValue(valueString);
|
1265
|
fn(this.value);
|
1266
|
};
|
1267
|
}
|
1268
|
/**
|
1269
|
* @param {?} fn
|
1270
|
* @return {?}
|
1271
|
*/
|
1272
|
registerOnTouched(fn) { this.onTouched = fn; }
|
1273
|
/**
|
1274
|
* @param {?} isDisabled
|
1275
|
* @return {?}
|
1276
|
*/
|
1277
|
setDisabledState(isDisabled) {
|
1278
|
this._renderer.setProperty(this._elementRef.nativeElement, 'disabled', isDisabled);
|
1279
|
}
|
1280
|
/**
|
1281
|
* \@internal
|
1282
|
* @return {?}
|
1283
|
*/
|
1284
|
_registerOption() { return (this._idCounter++).toString(); }
|
1285
|
/**
|
1286
|
* \@internal
|
1287
|
* @param {?} value
|
1288
|
* @return {?}
|
1289
|
*/
|
1290
|
_getOptionId(value) {
|
1291
|
for (const /** @type {?} */ id of Array.from(this._optionMap.keys())) {
|
1292
|
if (this._compareWith(this._optionMap.get(id), value))
|
1293
|
return id;
|
1294
|
}
|
1295
|
return null;
|
1296
|
}
|
1297
|
/**
|
1298
|
* \@internal
|
1299
|
* @param {?} valueString
|
1300
|
* @return {?}
|
1301
|
*/
|
1302
|
_getOptionValue(valueString) {
|
1303
|
const /** @type {?} */ id = _extractId(valueString);
|
1304
|
return this._optionMap.has(id) ? this._optionMap.get(id) : valueString;
|
1305
|
}
|
1306
|
}
|
1307
|
SelectControlValueAccessor.decorators = [
|
1308
|
{ type: Directive, args: [{
|
1309
|
selector: 'select:not([multiple])[formControlName],select:not([multiple])[formControl],select:not([multiple])[ngModel]',
|
1310
|
host: { '(change)': 'onChange($event.target.value)', '(blur)': 'onTouched()' },
|
1311
|
providers: [SELECT_VALUE_ACCESSOR]
|
1312
|
},] },
|
1313
|
];
|
1314
|
/**
|
1315
|
* @nocollapse
|
1316
|
*/
|
1317
|
SelectControlValueAccessor.ctorParameters = () => [
|
1318
|
{ type: Renderer2, },
|
1319
|
{ type: ElementRef, },
|
1320
|
];
|
1321
|
SelectControlValueAccessor.propDecorators = {
|
1322
|
'compareWith': [{ type: Input },],
|
1323
|
};
|
1324
|
/**
|
1325
|
* \@whatItDoes Marks `<option>` as dynamic, so Angular can be notified when options change.
|
1326
|
*
|
1327
|
* \@howToUse
|
1328
|
*
|
1329
|
* See docs for {\@link SelectControlValueAccessor} for usage examples.
|
1330
|
*
|
1331
|
* \@stable
|
1332
|
*/
|
1333
|
class NgSelectOption {
|
1334
|
/**
|
1335
|
* @param {?} _element
|
1336
|
* @param {?} _renderer
|
1337
|
* @param {?} _select
|
1338
|
*/
|
1339
|
constructor(_element, _renderer, _select) {
|
1340
|
this._element = _element;
|
1341
|
this._renderer = _renderer;
|
1342
|
this._select = _select;
|
1343
|
if (this._select)
|
1344
|
this.id = this._select._registerOption();
|
1345
|
}
|
1346
|
/**
|
1347
|
* @param {?} value
|
1348
|
* @return {?}
|
1349
|
*/
|
1350
|
set ngValue(value) {
|
1351
|
if (this._select == null)
|
1352
|
return;
|
1353
|
this._select._optionMap.set(this.id, value);
|
1354
|
this._setElementValue(_buildValueString(this.id, value));
|
1355
|
this._select.writeValue(this._select.value);
|
1356
|
}
|
1357
|
/**
|
1358
|
* @param {?} value
|
1359
|
* @return {?}
|
1360
|
*/
|
1361
|
set value(value) {
|
1362
|
this._setElementValue(value);
|
1363
|
if (this._select)
|
1364
|
this._select.writeValue(this._select.value);
|
1365
|
}
|
1366
|
/**
|
1367
|
* \@internal
|
1368
|
* @param {?} value
|
1369
|
* @return {?}
|
1370
|
*/
|
1371
|
_setElementValue(value) {
|
1372
|
this._renderer.setProperty(this._element.nativeElement, 'value', value);
|
1373
|
}
|
1374
|
/**
|
1375
|
* @return {?}
|
1376
|
*/
|
1377
|
ngOnDestroy() {
|
1378
|
if (this._select) {
|
1379
|
this._select._optionMap.delete(this.id);
|
1380
|
this._select.writeValue(this._select.value);
|
1381
|
}
|
1382
|
}
|
1383
|
}
|
1384
|
NgSelectOption.decorators = [
|
1385
|
{ type: Directive, args: [{ selector: 'option' },] },
|
1386
|
];
|
1387
|
/**
|
1388
|
* @nocollapse
|
1389
|
*/
|
1390
|
NgSelectOption.ctorParameters = () => [
|
1391
|
{ type: ElementRef, },
|
1392
|
{ type: Renderer2, },
|
1393
|
{ type: SelectControlValueAccessor, decorators: [{ type: Optional }, { type: Host },] },
|
1394
|
];
|
1395
|
NgSelectOption.propDecorators = {
|
1396
|
'ngValue': [{ type: Input, args: ['ngValue',] },],
|
1397
|
'value': [{ type: Input, args: ['value',] },],
|
1398
|
};
|
1399
|
|
1400
|
/**
|
1401
|
* @license
|
1402
|
* Copyright Google Inc. All Rights Reserved.
|
1403
|
*
|
1404
|
* Use of this source code is governed by an MIT-style license that can be
|
1405
|
* found in the LICENSE file at https://angular.io/license
|
1406
|
*/
|
1407
|
const SELECT_MULTIPLE_VALUE_ACCESSOR = {
|
1408
|
provide: NG_VALUE_ACCESSOR,
|
1409
|
useExisting: forwardRef(() => SelectMultipleControlValueAccessor),
|
1410
|
multi: true
|
1411
|
};
|
1412
|
/**
|
1413
|
* @param {?} id
|
1414
|
* @param {?} value
|
1415
|
* @return {?}
|
1416
|
*/
|
1417
|
function _buildValueString$1(id, value) {
|
1418
|
if (id == null)
|
1419
|
return `${value}`;
|
1420
|
if (typeof value === 'string')
|
1421
|
value = `'${value}'`;
|
1422
|
if (value && typeof value === 'object')
|
1423
|
value = 'Object';
|
1424
|
return `${id}: ${value}`.slice(0, 50);
|
1425
|
}
|
1426
|
/**
|
1427
|
* @param {?} valueString
|
1428
|
* @return {?}
|
1429
|
*/
|
1430
|
function _extractId$1(valueString) {
|
1431
|
return valueString.split(':')[0];
|
1432
|
}
|
1433
|
/**
|
1434
|
* The accessor for writing a value and listening to changes on a select element.
|
1435
|
*
|
1436
|
* ### Caveat: Options selection
|
1437
|
*
|
1438
|
* Angular uses object identity to select options. It's possible for the identities of items
|
1439
|
* to change while the data does not. This can happen, for example, if the items are produced
|
1440
|
* from an RPC to the server, and that RPC is re-run. Even if the data hasn't changed, the
|
1441
|
* second response will produce objects with different identities.
|
1442
|
*
|
1443
|
* To customize the default option comparison algorithm, `<select multiple>` supports `compareWith`
|
1444
|
* input. `compareWith` takes a **function** which has two arguments: `option1` and `option2`.
|
1445
|
* If `compareWith` is given, Angular selects options by the return value of the function.
|
1446
|
*
|
1447
|
* #### Syntax
|
1448
|
*
|
1449
|
* ```
|
1450
|
* <select multiple [compareWith]="compareFn" [(ngModel)]="selectedCountries">
|
1451
|
* <option *ngFor="let country of countries" [ngValue]="country">
|
1452
|
* {{country.name}}
|
1453
|
* </option>
|
1454
|
* </select>
|
1455
|
*
|
1456
|
* compareFn(c1: Country, c2: Country): boolean {
|
1457
|
* return c1 && c2 ? c1.id === c2.id : c1 === c2;
|
1458
|
* }
|
1459
|
* ```
|
1460
|
*
|
1461
|
* \@stable
|
1462
|
*/
|
1463
|
class SelectMultipleControlValueAccessor {
|
1464
|
/**
|
1465
|
* @param {?} _renderer
|
1466
|
* @param {?} _elementRef
|
1467
|
*/
|
1468
|
constructor(_renderer, _elementRef) {
|
1469
|
this._renderer = _renderer;
|
1470
|
this._elementRef = _elementRef;
|
1471
|
/**
|
1472
|
* \@internal
|
1473
|
*/
|
1474
|
this._optionMap = new Map();
|
1475
|
/**
|
1476
|
* \@internal
|
1477
|
*/
|
1478
|
this._idCounter = 0;
|
1479
|
this.onChange = (_) => { };
|
1480
|
this.onTouched = () => { };
|
1481
|
this._compareWith = ɵlooseIdentical;
|
1482
|
}
|
1483
|
/**
|
1484
|
* @param {?} fn
|
1485
|
* @return {?}
|
1486
|
*/
|
1487
|
set compareWith(fn) {
|
1488
|
if (typeof fn !== 'function') {
|
1489
|
throw new Error(`compareWith must be a function, but received ${JSON.stringify(fn)}`);
|
1490
|
}
|
1491
|
this._compareWith = fn;
|
1492
|
}
|
1493
|
/**
|
1494
|
* @param {?} value
|
1495
|
* @return {?}
|
1496
|
*/
|
1497
|
writeValue(value) {
|
1498
|
this.value = value;
|
1499
|
let /** @type {?} */ optionSelectedStateSetter;
|
1500
|
if (Array.isArray(value)) {
|
1501
|
// convert values to ids
|
1502
|
const /** @type {?} */ ids = value.map((v) => this._getOptionId(v));
|
1503
|
optionSelectedStateSetter = (opt, o) => { opt._setSelected(ids.indexOf(o.toString()) > -1); };
|
1504
|
}
|
1505
|
else {
|
1506
|
optionSelectedStateSetter = (opt, o) => { opt._setSelected(false); };
|
1507
|
}
|
1508
|
this._optionMap.forEach(optionSelectedStateSetter);
|
1509
|
}
|
1510
|
/**
|
1511
|
* @param {?} fn
|
1512
|
* @return {?}
|
1513
|
*/
|
1514
|
registerOnChange(fn) {
|
1515
|
this.onChange = (_) => {
|
1516
|
const /** @type {?} */ selected = [];
|
1517
|
if (_.hasOwnProperty('selectedOptions')) {
|
1518
|
const /** @type {?} */ options = _.selectedOptions;
|
1519
|
for (let /** @type {?} */ i = 0; i < options.length; i++) {
|
1520
|
const /** @type {?} */ opt = options.item(i);
|
1521
|
const /** @type {?} */ val = this._getOptionValue(opt.value);
|
1522
|
selected.push(val);
|
1523
|
}
|
1524
|
}
|
1525
|
else {
|
1526
|
const /** @type {?} */ options = (_.options);
|
1527
|
for (let /** @type {?} */ i = 0; i < options.length; i++) {
|
1528
|
const /** @type {?} */ opt = options.item(i);
|
1529
|
if (opt.selected) {
|
1530
|
const /** @type {?} */ val = this._getOptionValue(opt.value);
|
1531
|
selected.push(val);
|
1532
|
}
|
1533
|
}
|
1534
|
}
|
1535
|
this.value = selected;
|
1536
|
fn(selected);
|
1537
|
};
|
1538
|
}
|
1539
|
/**
|
1540
|
* @param {?} fn
|
1541
|
* @return {?}
|
1542
|
*/
|
1543
|
registerOnTouched(fn) { this.onTouched = fn; }
|
1544
|
/**
|
1545
|
* @param {?} isDisabled
|
1546
|
* @return {?}
|
1547
|
*/
|
1548
|
setDisabledState(isDisabled) {
|
1549
|
this._renderer.setProperty(this._elementRef.nativeElement, 'disabled', isDisabled);
|
1550
|
}
|
1551
|
/**
|
1552
|
* \@internal
|
1553
|
* @param {?} value
|
1554
|
* @return {?}
|
1555
|
*/
|
1556
|
_registerOption(value) {
|
1557
|
const /** @type {?} */ id = (this._idCounter++).toString();
|
1558
|
this._optionMap.set(id, value);
|
1559
|
return id;
|
1560
|
}
|
1561
|
/**
|
1562
|
* \@internal
|
1563
|
* @param {?} value
|
1564
|
* @return {?}
|
1565
|
*/
|
1566
|
_getOptionId(value) {
|
1567
|
for (const /** @type {?} */ id of Array.from(this._optionMap.keys())) {
|
1568
|
if (this._compareWith(/** @type {?} */ ((this._optionMap.get(id)))._value, value))
|
1569
|
return id;
|
1570
|
}
|
1571
|
return null;
|
1572
|
}
|
1573
|
/**
|
1574
|
* \@internal
|
1575
|
* @param {?} valueString
|
1576
|
* @return {?}
|
1577
|
*/
|
1578
|
_getOptionValue(valueString) {
|
1579
|
const /** @type {?} */ id = _extractId$1(valueString);
|
1580
|
return this._optionMap.has(id) ? ((this._optionMap.get(id)))._value : valueString;
|
1581
|
}
|
1582
|
}
|
1583
|
SelectMultipleControlValueAccessor.decorators = [
|
1584
|
{ type: Directive, args: [{
|
1585
|
selector: 'select[multiple][formControlName],select[multiple][formControl],select[multiple][ngModel]',
|
1586
|
host: { '(change)': 'onChange($event.target)', '(blur)': 'onTouched()' },
|
1587
|
providers: [SELECT_MULTIPLE_VALUE_ACCESSOR]
|
1588
|
},] },
|
1589
|
];
|
1590
|
/**
|
1591
|
* @nocollapse
|
1592
|
*/
|
1593
|
SelectMultipleControlValueAccessor.ctorParameters = () => [
|
1594
|
{ type: Renderer2, },
|
1595
|
{ type: ElementRef, },
|
1596
|
];
|
1597
|
SelectMultipleControlValueAccessor.propDecorators = {
|
1598
|
'compareWith': [{ type: Input },],
|
1599
|
};
|
1600
|
/**
|
1601
|
* Marks `<option>` as dynamic, so Angular can be notified when options change.
|
1602
|
*
|
1603
|
* ### Example
|
1604
|
*
|
1605
|
* ```
|
1606
|
* <select multiple name="city" ngModel>
|
1607
|
* <option *ngFor="let c of cities" [value]="c"></option>
|
1608
|
* </select>
|
1609
|
* ```
|
1610
|
*/
|
1611
|
class NgSelectMultipleOption {
|
1612
|
/**
|
1613
|
* @param {?} _element
|
1614
|
* @param {?} _renderer
|
1615
|
* @param {?} _select
|
1616
|
*/
|
1617
|
constructor(_element, _renderer, _select) {
|
1618
|
this._element = _element;
|
1619
|
this._renderer = _renderer;
|
1620
|
this._select = _select;
|
1621
|
if (this._select) {
|
1622
|
this.id = this._select._registerOption(this);
|
1623
|
}
|
1624
|
}
|
1625
|
/**
|
1626
|
* @param {?} value
|
1627
|
* @return {?}
|
1628
|
*/
|
1629
|
set ngValue(value) {
|
1630
|
if (this._select == null)
|
1631
|
return;
|
1632
|
this._value = value;
|
1633
|
this._setElementValue(_buildValueString$1(this.id, value));
|
1634
|
this._select.writeValue(this._select.value);
|
1635
|
}
|
1636
|
/**
|
1637
|
* @param {?} value
|
1638
|
* @return {?}
|
1639
|
*/
|
1640
|
set value(value) {
|
1641
|
if (this._select) {
|
1642
|
this._value = value;
|
1643
|
this._setElementValue(_buildValueString$1(this.id, value));
|
1644
|
this._select.writeValue(this._select.value);
|
1645
|
}
|
1646
|
else {
|
1647
|
this._setElementValue(value);
|
1648
|
}
|
1649
|
}
|
1650
|
/**
|
1651
|
* \@internal
|
1652
|
* @param {?} value
|
1653
|
* @return {?}
|
1654
|
*/
|
1655
|
_setElementValue(value) {
|
1656
|
this._renderer.setProperty(this._element.nativeElement, 'value', value);
|
1657
|
}
|
1658
|
/**
|
1659
|
* \@internal
|
1660
|
* @param {?} selected
|
1661
|
* @return {?}
|
1662
|
*/
|
1663
|
_setSelected(selected) {
|
1664
|
this._renderer.setProperty(this._element.nativeElement, 'selected', selected);
|
1665
|
}
|
1666
|
/**
|
1667
|
* @return {?}
|
1668
|
*/
|
1669
|
ngOnDestroy() {
|
1670
|
if (this._select) {
|
1671
|
this._select._optionMap.delete(this.id);
|
1672
|
this._select.writeValue(this._select.value);
|
1673
|
}
|
1674
|
}
|
1675
|
}
|
1676
|
NgSelectMultipleOption.decorators = [
|
1677
|
{ type: Directive, args: [{ selector: 'option' },] },
|
1678
|
];
|
1679
|
/**
|
1680
|
* @nocollapse
|
1681
|
*/
|
1682
|
NgSelectMultipleOption.ctorParameters = () => [
|
1683
|
{ type: ElementRef, },
|
1684
|
{ type: Renderer2, },
|
1685
|
{ type: SelectMultipleControlValueAccessor, decorators: [{ type: Optional }, { type: Host },] },
|
1686
|
];
|
1687
|
NgSelectMultipleOption.propDecorators = {
|
1688
|
'ngValue': [{ type: Input, args: ['ngValue',] },],
|
1689
|
'value': [{ type: Input, args: ['value',] },],
|
1690
|
};
|
1691
|
|
1692
|
/**
|
1693
|
* @license
|
1694
|
* Copyright Google Inc. All Rights Reserved.
|
1695
|
*
|
1696
|
* Use of this source code is governed by an MIT-style license that can be
|
1697
|
* found in the LICENSE file at https://angular.io/license
|
1698
|
*/
|
1699
|
/**
|
1700
|
* @param {?} name
|
1701
|
* @param {?} parent
|
1702
|
* @return {?}
|
1703
|
*/
|
1704
|
function controlPath(name, parent) {
|
1705
|
return [...((parent.path)), name];
|
1706
|
}
|
1707
|
/**
|
1708
|
* @param {?} control
|
1709
|
* @param {?} dir
|
1710
|
* @return {?}
|
1711
|
*/
|
1712
|
function setUpControl(control, dir) {
|
1713
|
if (!control)
|
1714
|
_throwError(dir, 'Cannot find control with');
|
1715
|
if (!dir.valueAccessor)
|
1716
|
_throwError(dir, 'No value accessor for form control with');
|
1717
|
control.validator = Validators.compose([/** @type {?} */ ((control.validator)), dir.validator]);
|
1718
|
control.asyncValidator = Validators.composeAsync([/** @type {?} */ ((control.asyncValidator)), dir.asyncValidator]); /** @type {?} */
|
1719
|
((dir.valueAccessor)).writeValue(control.value); /** @type {?} */
|
1720
|
((
|
1721
|
// view -> model
|
1722
|
dir.valueAccessor)).registerOnChange((newValue) => {
|
1723
|
dir.viewToModelUpdate(newValue);
|
1724
|
control.markAsDirty();
|
1725
|
control.setValue(newValue, { emitModelToViewChange: false });
|
1726
|
}); /** @type {?} */
|
1727
|
((
|
1728
|
// touched
|
1729
|
dir.valueAccessor)).registerOnTouched(() => control.markAsTouched());
|
1730
|
control.registerOnChange((newValue, emitModelEvent) => {
|
1731
|
((
|
1732
|
// control -> view
|
1733
|
dir.valueAccessor)).writeValue(newValue);
|
1734
|
// control -> ngModel
|
1735
|
if (emitModelEvent)
|
1736
|
dir.viewToModelUpdate(newValue);
|
1737
|
});
|
1738
|
if (((dir.valueAccessor)).setDisabledState) {
|
1739
|
control.registerOnDisabledChange((isDisabled) => { /** @type {?} */ ((((dir.valueAccessor)).setDisabledState))(isDisabled); });
|
1740
|
}
|
1741
|
// re-run validation when validator binding changes, e.g. minlength=3 -> minlength=4
|
1742
|
dir._rawValidators.forEach((validator) => {
|
1743
|
if (((validator)).registerOnValidatorChange)
|
1744
|
((((validator)).registerOnValidatorChange))(() => control.updateValueAndValidity());
|
1745
|
});
|
1746
|
dir._rawAsyncValidators.forEach((validator) => {
|
1747
|
if (((validator)).registerOnValidatorChange)
|
1748
|
((((validator)).registerOnValidatorChange))(() => control.updateValueAndValidity());
|
1749
|
});
|
1750
|
}
|
1751
|
/**
|
1752
|
* @param {?} control
|
1753
|
* @param {?} dir
|
1754
|
* @return {?}
|
1755
|
*/
|
1756
|
function cleanUpControl(control, dir) {
|
1757
|
((dir.valueAccessor)).registerOnChange(() => _noControlError(dir)); /** @type {?} */
|
1758
|
((dir.valueAccessor)).registerOnTouched(() => _noControlError(dir));
|
1759
|
dir._rawValidators.forEach((validator) => {
|
1760
|
if (validator.registerOnValidatorChange) {
|
1761
|
validator.registerOnValidatorChange(null);
|
1762
|
}
|
1763
|
});
|
1764
|
dir._rawAsyncValidators.forEach((validator) => {
|
1765
|
if (validator.registerOnValidatorChange) {
|
1766
|
validator.registerOnValidatorChange(null);
|
1767
|
}
|
1768
|
});
|
1769
|
if (control)
|
1770
|
control._clearChangeFns();
|
1771
|
}
|
1772
|
/**
|
1773
|
* @param {?} control
|
1774
|
* @param {?} dir
|
1775
|
* @return {?}
|
1776
|
*/
|
1777
|
function setUpFormContainer(control, dir) {
|
1778
|
if (control == null)
|
1779
|
_throwError(dir, 'Cannot find control with');
|
1780
|
control.validator = Validators.compose([control.validator, dir.validator]);
|
1781
|
control.asyncValidator = Validators.composeAsync([control.asyncValidator, dir.asyncValidator]);
|
1782
|
}
|
1783
|
/**
|
1784
|
* @param {?} dir
|
1785
|
* @return {?}
|
1786
|
*/
|
1787
|
function _noControlError(dir) {
|
1788
|
return _throwError(dir, 'There is no FormControl instance attached to form control element with');
|
1789
|
}
|
1790
|
/**
|
1791
|
* @param {?} dir
|
1792
|
* @param {?} message
|
1793
|
* @return {?}
|
1794
|
*/
|
1795
|
function _throwError(dir, message) {
|
1796
|
let /** @type {?} */ messageEnd;
|
1797
|
if (((dir.path)).length > 1) {
|
1798
|
messageEnd = `path: '${ /** @type {?} */((dir.path)).join(' -> ')}'`;
|
1799
|
}
|
1800
|
else if (((dir.path))[0]) {
|
1801
|
messageEnd = `name: '${dir.path}'`;
|
1802
|
}
|
1803
|
else {
|
1804
|
messageEnd = 'unspecified name attribute';
|
1805
|
}
|
1806
|
throw new Error(`${message} ${messageEnd}`);
|
1807
|
}
|
1808
|
/**
|
1809
|
* @param {?} validators
|
1810
|
* @return {?}
|
1811
|
*/
|
1812
|
function composeValidators(validators) {
|
1813
|
return validators != null ? Validators.compose(validators.map(normalizeValidator)) : null;
|
1814
|
}
|
1815
|
/**
|
1816
|
* @param {?} validators
|
1817
|
* @return {?}
|
1818
|
*/
|
1819
|
function composeAsyncValidators(validators) {
|
1820
|
return validators != null ? Validators.composeAsync(validators.map(normalizeAsyncValidator)) :
|
1821
|
null;
|
1822
|
}
|
1823
|
/**
|
1824
|
* @param {?} changes
|
1825
|
* @param {?} viewModel
|
1826
|
* @return {?}
|
1827
|
*/
|
1828
|
function isPropertyUpdated(changes, viewModel) {
|
1829
|
if (!changes.hasOwnProperty('model'))
|
1830
|
return false;
|
1831
|
const /** @type {?} */ change = changes['model'];
|
1832
|
if (change.isFirstChange())
|
1833
|
return true;
|
1834
|
return !ɵlooseIdentical(viewModel, change.currentValue);
|
1835
|
}
|
1836
|
const BUILTIN_ACCESSORS = [
|
1837
|
CheckboxControlValueAccessor,
|
1838
|
RangeValueAccessor,
|
1839
|
NumberValueAccessor,
|
1840
|
SelectControlValueAccessor,
|
1841
|
SelectMultipleControlValueAccessor,
|
1842
|
RadioControlValueAccessor,
|
1843
|
];
|
1844
|
/**
|
1845
|
* @param {?} valueAccessor
|
1846
|
* @return {?}
|
1847
|
*/
|
1848
|
function isBuiltInAccessor(valueAccessor) {
|
1849
|
return BUILTIN_ACCESSORS.some(a => valueAccessor.constructor === a);
|
1850
|
}
|
1851
|
/**
|
1852
|
* @param {?} dir
|
1853
|
* @param {?} valueAccessors
|
1854
|
* @return {?}
|
1855
|
*/
|
1856
|
function selectValueAccessor(dir, valueAccessors) {
|
1857
|
if (!valueAccessors)
|
1858
|
return null;
|
1859
|
let /** @type {?} */ defaultAccessor = undefined;
|
1860
|
let /** @type {?} */ builtinAccessor = undefined;
|
1861
|
let /** @type {?} */ customAccessor = undefined;
|
1862
|
valueAccessors.forEach((v) => {
|
1863
|
if (v.constructor === DefaultValueAccessor) {
|
1864
|
defaultAccessor = v;
|
1865
|
}
|
1866
|
else if (isBuiltInAccessor(v)) {
|
1867
|
if (builtinAccessor)
|
1868
|
_throwError(dir, 'More than one built-in value accessor matches form control with');
|
1869
|
builtinAccessor = v;
|
1870
|
}
|
1871
|
else {
|
1872
|
if (customAccessor)
|
1873
|
_throwError(dir, 'More than one custom value accessor matches form control with');
|
1874
|
customAccessor = v;
|
1875
|
}
|
1876
|
});
|
1877
|
if (customAccessor)
|
1878
|
return customAccessor;
|
1879
|
if (builtinAccessor)
|
1880
|
return builtinAccessor;
|
1881
|
if (defaultAccessor)
|
1882
|
return defaultAccessor;
|
1883
|
_throwError(dir, 'No valid value accessor for form control with');
|
1884
|
return null;
|
1885
|
}
|
1886
|
|
1887
|
/**
|
1888
|
* @license
|
1889
|
* Copyright Google Inc. All Rights Reserved.
|
1890
|
*
|
1891
|
* Use of this source code is governed by an MIT-style license that can be
|
1892
|
* found in the LICENSE file at https://angular.io/license
|
1893
|
*/
|
1894
|
/**
|
1895
|
* This is a base class for code shared between {\@link NgModelGroup} and {\@link FormGroupName}.
|
1896
|
*
|
1897
|
* \@stable
|
1898
|
*/
|
1899
|
class AbstractFormGroupDirective extends ControlContainer {
|
1900
|
/**
|
1901
|
* @return {?}
|
1902
|
*/
|
1903
|
ngOnInit() {
|
1904
|
this._checkParentType(); /** @type {?} */
|
1905
|
((this.formDirective)).addFormGroup(this);
|
1906
|
}
|
1907
|
/**
|
1908
|
* @return {?}
|
1909
|
*/
|
1910
|
ngOnDestroy() {
|
1911
|
if (this.formDirective) {
|
1912
|
this.formDirective.removeFormGroup(this);
|
1913
|
}
|
1914
|
}
|
1915
|
/**
|
1916
|
* Get the {\@link FormGroup} backing this binding.
|
1917
|
* @return {?}
|
1918
|
*/
|
1919
|
get control() { return ((this.formDirective)).getFormGroup(this); }
|
1920
|
/**
|
1921
|
* Get the path to this control group.
|
1922
|
* @return {?}
|
1923
|
*/
|
1924
|
get path() { return controlPath(this.name, this._parent); }
|
1925
|
/**
|
1926
|
* Get the {\@link Form} to which this group belongs.
|
1927
|
* @return {?}
|
1928
|
*/
|
1929
|
get formDirective() { return this._parent ? this._parent.formDirective : null; }
|
1930
|
/**
|
1931
|
* @return {?}
|
1932
|
*/
|
1933
|
get validator() { return composeValidators(this._validators); }
|
1934
|
/**
|
1935
|
* @return {?}
|
1936
|
*/
|
1937
|
get asyncValidator() {
|
1938
|
return composeAsyncValidators(this._asyncValidators);
|
1939
|
}
|
1940
|
/**
|
1941
|
* \@internal
|
1942
|
* @return {?}
|
1943
|
*/
|
1944
|
_checkParentType() { }
|
1945
|
}
|
1946
|
|
1947
|
/**
|
1948
|
* @license
|
1949
|
* Copyright Google Inc. All Rights Reserved.
|
1950
|
*
|
1951
|
* Use of this source code is governed by an MIT-style license that can be
|
1952
|
* found in the LICENSE file at https://angular.io/license
|
1953
|
*/
|
1954
|
class AbstractControlStatus {
|
1955
|
/**
|
1956
|
* @param {?} cd
|
1957
|
*/
|
1958
|
constructor(cd) { this._cd = cd; }
|
1959
|
/**
|
1960
|
* @return {?}
|
1961
|
*/
|
1962
|
get ngClassUntouched() { return this._cd.control ? this._cd.control.untouched : false; }
|
1963
|
/**
|
1964
|
* @return {?}
|
1965
|
*/
|
1966
|
get ngClassTouched() { return this._cd.control ? this._cd.control.touched : false; }
|
1967
|
/**
|
1968
|
* @return {?}
|
1969
|
*/
|
1970
|
get ngClassPristine() { return this._cd.control ? this._cd.control.pristine : false; }
|
1971
|
/**
|
1972
|
* @return {?}
|
1973
|
*/
|
1974
|
get ngClassDirty() { return this._cd.control ? this._cd.control.dirty : false; }
|
1975
|
/**
|
1976
|
* @return {?}
|
1977
|
*/
|
1978
|
get ngClassValid() { return this._cd.control ? this._cd.control.valid : false; }
|
1979
|
/**
|
1980
|
* @return {?}
|
1981
|
*/
|
1982
|
get ngClassInvalid() { return this._cd.control ? this._cd.control.invalid : false; }
|
1983
|
/**
|
1984
|
* @return {?}
|
1985
|
*/
|
1986
|
get ngClassPending() { return this._cd.control ? this._cd.control.pending : false; }
|
1987
|
}
|
1988
|
const ngControlStatusHost = {
|
1989
|
'[class.ng-untouched]': 'ngClassUntouched',
|
1990
|
'[class.ng-touched]': 'ngClassTouched',
|
1991
|
'[class.ng-pristine]': 'ngClassPristine',
|
1992
|
'[class.ng-dirty]': 'ngClassDirty',
|
1993
|
'[class.ng-valid]': 'ngClassValid',
|
1994
|
'[class.ng-invalid]': 'ngClassInvalid',
|
1995
|
'[class.ng-pending]': 'ngClassPending',
|
1996
|
};
|
1997
|
/**
|
1998
|
* Directive automatically applied to Angular form controls that sets CSS classes
|
1999
|
* based on control status. The following classes are applied as the properties
|
2000
|
* become true:
|
2001
|
*
|
2002
|
* * ng-valid
|
2003
|
* * ng-invalid
|
2004
|
* * ng-pending
|
2005
|
* * ng-pristine
|
2006
|
* * ng-dirty
|
2007
|
* * ng-untouched
|
2008
|
* * ng-touched
|
2009
|
*
|
2010
|
* \@stable
|
2011
|
*/
|
2012
|
class NgControlStatus extends AbstractControlStatus {
|
2013
|
/**
|
2014
|
* @param {?} cd
|
2015
|
*/
|
2016
|
constructor(cd) { super(cd); }
|
2017
|
}
|
2018
|
NgControlStatus.decorators = [
|
2019
|
{ type: Directive, args: [{ selector: '[formControlName],[ngModel],[formControl]', host: ngControlStatusHost },] },
|
2020
|
];
|
2021
|
/**
|
2022
|
* @nocollapse
|
2023
|
*/
|
2024
|
NgControlStatus.ctorParameters = () => [
|
2025
|
{ type: NgControl, decorators: [{ type: Self },] },
|
2026
|
];
|
2027
|
/**
|
2028
|
* Directive automatically applied to Angular form groups that sets CSS classes
|
2029
|
* based on control status (valid/invalid/dirty/etc).
|
2030
|
*
|
2031
|
* \@stable
|
2032
|
*/
|
2033
|
class NgControlStatusGroup extends AbstractControlStatus {
|
2034
|
/**
|
2035
|
* @param {?} cd
|
2036
|
*/
|
2037
|
constructor(cd) { super(cd); }
|
2038
|
}
|
2039
|
NgControlStatusGroup.decorators = [
|
2040
|
{ type: Directive, args: [{
|
2041
|
selector: '[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]',
|
2042
|
host: ngControlStatusHost
|
2043
|
},] },
|
2044
|
];
|
2045
|
/**
|
2046
|
* @nocollapse
|
2047
|
*/
|
2048
|
NgControlStatusGroup.ctorParameters = () => [
|
2049
|
{ type: ControlContainer, decorators: [{ type: Self },] },
|
2050
|
];
|
2051
|
|
2052
|
/**
|
2053
|
* @license
|
2054
|
* Copyright Google Inc. All Rights Reserved.
|
2055
|
*
|
2056
|
* Use of this source code is governed by an MIT-style license that can be
|
2057
|
* found in the LICENSE file at https://angular.io/license
|
2058
|
*/
|
2059
|
/**
|
2060
|
* Indicates that a FormControl is valid, i.e. that no errors exist in the input value.
|
2061
|
*/
|
2062
|
const VALID = 'VALID';
|
2063
|
/**
|
2064
|
* Indicates that a FormControl is invalid, i.e. that an error exists in the input value.
|
2065
|
*/
|
2066
|
const INVALID = 'INVALID';
|
2067
|
/**
|
2068
|
* Indicates that a FormControl is pending, i.e. that async validation is occurring and
|
2069
|
* errors are not yet available for the input value.
|
2070
|
*/
|
2071
|
const PENDING = 'PENDING';
|
2072
|
/**
|
2073
|
* Indicates that a FormControl is disabled, i.e. that the control is exempt from ancestor
|
2074
|
* calculations of validity or value.
|
2075
|
*/
|
2076
|
const DISABLED = 'DISABLED';
|
2077
|
/**
|
2078
|
* @param {?} control
|
2079
|
* @param {?} path
|
2080
|
* @param {?} delimiter
|
2081
|
* @return {?}
|
2082
|
*/
|
2083
|
function _find(control, path, delimiter) {
|
2084
|
if (path == null)
|
2085
|
return null;
|
2086
|
if (!(path instanceof Array)) {
|
2087
|
path = ((path)).split(delimiter);
|
2088
|
}
|
2089
|
if (path instanceof Array && (path.length === 0))
|
2090
|
return null;
|
2091
|
return ((path)).reduce((v, name) => {
|
2092
|
if (v instanceof FormGroup) {
|
2093
|
return v.controls[name] || null;
|
2094
|
}
|
2095
|
if (v instanceof FormArray) {
|
2096
|
return v.at(/** @type {?} */ (name)) || null;
|
2097
|
}
|
2098
|
return null;
|
2099
|
}, control);
|
2100
|
}
|
2101
|
/**
|
2102
|
* @param {?=} validator
|
2103
|
* @return {?}
|
2104
|
*/
|
2105
|
function coerceToValidator(validator) {
|
2106
|
return Array.isArray(validator) ? composeValidators(validator) : validator || null;
|
2107
|
}
|
2108
|
/**
|
2109
|
* @param {?=} asyncValidator
|
2110
|
* @return {?}
|
2111
|
*/
|
2112
|
function coerceToAsyncValidator(asyncValidator) {
|
2113
|
return Array.isArray(asyncValidator) ? composeAsyncValidators(asyncValidator) :
|
2114
|
asyncValidator || null;
|
2115
|
}
|
2116
|
/**
|
2117
|
* \@whatItDoes This is the base class for {\@link FormControl}, {\@link FormGroup}, and
|
2118
|
* {\@link FormArray}.
|
2119
|
*
|
2120
|
* It provides some of the shared behavior that all controls and groups of controls have, like
|
2121
|
* running validators, calculating status, and resetting state. It also defines the properties
|
2122
|
* that are shared between all sub-classes, like `value`, `valid`, and `dirty`. It shouldn't be
|
2123
|
* instantiated directly.
|
2124
|
*
|
2125
|
* \@stable
|
2126
|
* @abstract
|
2127
|
*/
|
2128
|
class AbstractControl {
|
2129
|
/**
|
2130
|
* @param {?} validator
|
2131
|
* @param {?} asyncValidator
|
2132
|
*/
|
2133
|
constructor(validator, asyncValidator) {
|
2134
|
this.validator = validator;
|
2135
|
this.asyncValidator = asyncValidator;
|
2136
|
/**
|
2137
|
* \@internal
|
2138
|
*/
|
2139
|
this._onCollectionChange = () => { };
|
2140
|
this._pristine = true;
|
2141
|
this._touched = false;
|
2142
|
/**
|
2143
|
* \@internal
|
2144
|
*/
|
2145
|
this._onDisabledChange = [];
|
2146
|
}
|
2147
|
/**
|
2148
|
* The value of the control.
|
2149
|
* @return {?}
|
2150
|
*/
|
2151
|
get value() { return this._value; }
|
2152
|
/**
|
2153
|
* The parent control.
|
2154
|
* @return {?}
|
2155
|
*/
|
2156
|
get parent() { return this._parent; }
|
2157
|
/**
|
2158
|
* The validation status of the control. There are four possible
|
2159
|
* validation statuses:
|
2160
|
*
|
2161
|
* * **VALID**: control has passed all validation checks
|
2162
|
* * **INVALID**: control has failed at least one validation check
|
2163
|
* * **PENDING**: control is in the midst of conducting a validation check
|
2164
|
* * **DISABLED**: control is exempt from validation checks
|
2165
|
*
|
2166
|
* These statuses are mutually exclusive, so a control cannot be
|
2167
|
* both valid AND invalid or invalid AND disabled.
|
2168
|
* @return {?}
|
2169
|
*/
|
2170
|
get status() { return this._status; }
|
2171
|
/**
|
2172
|
* A control is `valid` when its `status === VALID`.
|
2173
|
*
|
2174
|
* In order to have this status, the control must have passed all its
|
2175
|
* validation checks.
|
2176
|
* @return {?}
|
2177
|
*/
|
2178
|
get valid() { return this._status === VALID; }
|
2179
|
/**
|
2180
|
* A control is `invalid` when its `status === INVALID`.
|
2181
|
*
|
2182
|
* In order to have this status, the control must have failed
|
2183
|
* at least one of its validation checks.
|
2184
|
* @return {?}
|
2185
|
*/
|
2186
|
get invalid() { return this._status === INVALID; }
|
2187
|
/**
|
2188
|
* A control is `pending` when its `status === PENDING`.
|
2189
|
*
|
2190
|
* In order to have this status, the control must be in the
|
2191
|
* middle of conducting a validation check.
|
2192
|
* @return {?}
|
2193
|
*/
|
2194
|
get pending() { return this._status == PENDING; }
|
2195
|
/**
|
2196
|
* A control is `disabled` when its `status === DISABLED`.
|
2197
|
*
|
2198
|
* Disabled controls are exempt from validation checks and
|
2199
|
* are not included in the aggregate value of their ancestor
|
2200
|
* controls.
|
2201
|
* @return {?}
|
2202
|
*/
|
2203
|
get disabled() { return this._status === DISABLED; }
|
2204
|
/**
|
2205
|
* A control is `enabled` as long as its `status !== DISABLED`.
|
2206
|
*
|
2207
|
* In other words, it has a status of `VALID`, `INVALID`, or
|
2208
|
* `PENDING`.
|
2209
|
* @return {?}
|
2210
|
*/
|
2211
|
get enabled() { return this._status !== DISABLED; }
|
2212
|
/**
|
2213
|
* Returns any errors generated by failing validation. If there
|
2214
|
* are no errors, it will return null.
|
2215
|
* @return {?}
|
2216
|
*/
|
2217
|
get errors() { return this._errors; }
|
2218
|
/**
|
2219
|
* A control is `pristine` if the user has not yet changed
|
2220
|
* the value in the UI.
|
2221
|
*
|
2222
|
* Note that programmatic changes to a control's value will
|
2223
|
* *not* mark it dirty.
|
2224
|
* @return {?}
|
2225
|
*/
|
2226
|
get pristine() { return this._pristine; }
|
2227
|
/**
|
2228
|
* A control is `dirty` if the user has changed the value
|
2229
|
* in the UI.
|
2230
|
*
|
2231
|
* Note that programmatic changes to a control's value will
|
2232
|
* *not* mark it dirty.
|
2233
|
* @return {?}
|
2234
|
*/
|
2235
|
get dirty() { return !this.pristine; }
|
2236
|
/**
|
2237
|
* A control is marked `touched` once the user has triggered
|
2238
|
* a `blur` event on it.
|
2239
|
* @return {?}
|
2240
|
*/
|
2241
|
get touched() { return this._touched; }
|
2242
|
/**
|
2243
|
* A control is `untouched` if the user has not yet triggered
|
2244
|
* a `blur` event on it.
|
2245
|
* @return {?}
|
2246
|
*/
|
2247
|
get untouched() { return !this._touched; }
|
2248
|
/**
|
2249
|
* Emits an event every time the value of the control changes, in
|
2250
|
* the UI or programmatically.
|
2251
|
* @return {?}
|
2252
|
*/
|
2253
|
get valueChanges() { return this._valueChanges; }
|
2254
|
/**
|
2255
|
* Emits an event every time the validation status of the control
|
2256
|
* is re-calculated.
|
2257
|
* @return {?}
|
2258
|
*/
|
2259
|
get statusChanges() { return this._statusChanges; }
|
2260
|
/**
|
2261
|
* Sets the synchronous validators that are active on this control. Calling
|
2262
|
* this will overwrite any existing sync validators.
|
2263
|
* @param {?} newValidator
|
2264
|
* @return {?}
|
2265
|
*/
|
2266
|
setValidators(newValidator) {
|
2267
|
this.validator = coerceToValidator(newValidator);
|
2268
|
}
|
2269
|
/**
|
2270
|
* Sets the async validators that are active on this control. Calling this
|
2271
|
* will overwrite any existing async validators.
|
2272
|
* @param {?} newValidator
|
2273
|
* @return {?}
|
2274
|
*/
|
2275
|
setAsyncValidators(newValidator) {
|
2276
|
this.asyncValidator = coerceToAsyncValidator(newValidator);
|
2277
|
}
|
2278
|
/**
|
2279
|
* Empties out the sync validator list.
|
2280
|
* @return {?}
|
2281
|
*/
|
2282
|
clearValidators() { this.validator = null; }
|
2283
|
/**
|
2284
|
* Empties out the async validator list.
|
2285
|
* @return {?}
|
2286
|
*/
|
2287
|
clearAsyncValidators() { this.asyncValidator = null; }
|
2288
|
/**
|
2289
|
* Marks the control as `touched`.
|
2290
|
*
|
2291
|
* This will also mark all direct ancestors as `touched` to maintain
|
2292
|
* the model.
|
2293
|
* @param {?=} opts
|
2294
|
* @return {?}
|
2295
|
*/
|
2296
|
markAsTouched(opts = {}) {
|
2297
|
this._touched = true;
|
2298
|
if (this._parent && !opts.onlySelf) {
|
2299
|
this._parent.markAsTouched(opts);
|
2300
|
}
|
2301
|
}
|
2302
|
/**
|
2303
|
* Marks the control as `untouched`.
|
2304
|
*
|
2305
|
* If the control has any children, it will also mark all children as `untouched`
|
2306
|
* to maintain the model, and re-calculate the `touched` status of all parent
|
2307
|
* controls.
|
2308
|
* @param {?=} opts
|
2309
|
* @return {?}
|
2310
|
*/
|
2311
|
markAsUntouched(opts = {}) {
|
2312
|
this._touched = false;
|
2313
|
this._forEachChild((control) => { control.markAsUntouched({ onlySelf: true }); });
|
2314
|
if (this._parent && !opts.onlySelf) {
|
2315
|
this._parent._updateTouched(opts);
|
2316
|
}
|
2317
|
}
|
2318
|
/**
|
2319
|
* Marks the control as `dirty`.
|
2320
|
*
|
2321
|
* This will also mark all direct ancestors as `dirty` to maintain
|
2322
|
* the model.
|
2323
|
* @param {?=} opts
|
2324
|
* @return {?}
|
2325
|
*/
|
2326
|
markAsDirty(opts = {}) {
|
2327
|
this._pristine = false;
|
2328
|
if (this._parent && !opts.onlySelf) {
|
2329
|
this._parent.markAsDirty(opts);
|
2330
|
}
|
2331
|
}
|
2332
|
/**
|
2333
|
* Marks the control as `pristine`.
|
2334
|
*
|
2335
|
* If the control has any children, it will also mark all children as `pristine`
|
2336
|
* to maintain the model, and re-calculate the `pristine` status of all parent
|
2337
|
* controls.
|
2338
|
* @param {?=} opts
|
2339
|
* @return {?}
|
2340
|
*/
|
2341
|
markAsPristine(opts = {}) {
|
2342
|
this._pristine = true;
|
2343
|
this._forEachChild((control) => { control.markAsPristine({ onlySelf: true }); });
|
2344
|
if (this._parent && !opts.onlySelf) {
|
2345
|
this._parent._updatePristine(opts);
|
2346
|
}
|
2347
|
}
|
2348
|
/**
|
2349
|
* Marks the control as `pending`.
|
2350
|
* @param {?=} opts
|
2351
|
* @return {?}
|
2352
|
*/
|
2353
|
markAsPending(opts = {}) {
|
2354
|
this._status = PENDING;
|
2355
|
if (this._parent && !opts.onlySelf) {
|
2356
|
this._parent.markAsPending(opts);
|
2357
|
}
|
2358
|
}
|
2359
|
/**
|
2360
|
* Disables the control. This means the control will be exempt from validation checks and
|
2361
|
* excluded from the aggregate value of any parent. Its status is `DISABLED`.
|
2362
|
*
|
2363
|
* If the control has children, all children will be disabled to maintain the model.
|
2364
|
* @param {?=} opts
|
2365
|
* @return {?}
|
2366
|
*/
|
2367
|
disable(opts = {}) {
|
2368
|
this._status = DISABLED;
|
2369
|
this._errors = null;
|
2370
|
this._forEachChild((control) => { control.disable({ onlySelf: true }); });
|
2371
|
this._updateValue();
|
2372
|
if (opts.emitEvent !== false) {
|
2373
|
this._valueChanges.emit(this._value);
|
2374
|
this._statusChanges.emit(this._status);
|
2375
|
}
|
2376
|
this._updateAncestors(!!opts.onlySelf);
|
2377
|
this._onDisabledChange.forEach((changeFn) => changeFn(true));
|
2378
|
}
|
2379
|
/**
|
2380
|
* Enables the control. This means the control will be included in validation checks and
|
2381
|
* the aggregate value of its parent. Its status is re-calculated based on its value and
|
2382
|
* its validators.
|
2383
|
*
|
2384
|
* If the control has children, all children will be enabled.
|
2385
|
* @param {?=} opts
|
2386
|
* @return {?}
|
2387
|
*/
|
2388
|
enable(opts = {}) {
|
2389
|
this._status = VALID;
|
2390
|
this._forEachChild((control) => { control.enable({ onlySelf: true }); });
|
2391
|
this.updateValueAndValidity({ onlySelf: true, emitEvent: opts.emitEvent });
|
2392
|
this._updateAncestors(!!opts.onlySelf);
|
2393
|
this._onDisabledChange.forEach((changeFn) => changeFn(false));
|
2394
|
}
|
2395
|
/**
|
2396
|
* @param {?} onlySelf
|
2397
|
* @return {?}
|
2398
|
*/
|
2399
|
_updateAncestors(onlySelf) {
|
2400
|
if (this._parent && !onlySelf) {
|
2401
|
this._parent.updateValueAndValidity();
|
2402
|
this._parent._updatePristine();
|
2403
|
this._parent._updateTouched();
|
2404
|
}
|
2405
|
}
|
2406
|
/**
|
2407
|
* @param {?} parent
|
2408
|
* @return {?}
|
2409
|
*/
|
2410
|
setParent(parent) { this._parent = parent; }
|
2411
|
/**
|
2412
|
* Sets the value of the control. Abstract method (implemented in sub-classes).
|
2413
|
* @abstract
|
2414
|
* @param {?} value
|
2415
|
* @param {?=} options
|
2416
|
* @return {?}
|
2417
|
*/
|
2418
|
setValue(value, options) { }
|
2419
|
/**
|
2420
|
* Patches the value of the control. Abstract method (implemented in sub-classes).
|
2421
|
* @abstract
|
2422
|
* @param {?} value
|
2423
|
* @param {?=} options
|
2424
|
* @return {?}
|
2425
|
*/
|
2426
|
patchValue(value, options) { }
|
2427
|
/**
|
2428
|
* Resets the control. Abstract method (implemented in sub-classes).
|
2429
|
* @abstract
|
2430
|
* @param {?=} value
|
2431
|
* @param {?=} options
|
2432
|
* @return {?}
|
2433
|
*/
|
2434
|
reset(value, options) { }
|
2435
|
/**
|
2436
|
* Re-calculates the value and validation status of the control.
|
2437
|
*
|
2438
|
* By default, it will also update the value and validity of its ancestors.
|
2439
|
* @param {?=} opts
|
2440
|
* @return {?}
|
2441
|
*/
|
2442
|
updateValueAndValidity(opts = {}) {
|
2443
|
this._setInitialStatus();
|
2444
|
this._updateValue();
|
2445
|
if (this.enabled) {
|
2446
|
this._cancelExistingSubscription();
|
2447
|
this._errors = this._runValidator();
|
2448
|
this._status = this._calculateStatus();
|
2449
|
if (this._status === VALID || this._status === PENDING) {
|
2450
|
this._runAsyncValidator(opts.emitEvent);
|
2451
|
}
|
2452
|
}
|
2453
|
if (opts.emitEvent !== false) {
|
2454
|
this._valueChanges.emit(this._value);
|
2455
|
this._statusChanges.emit(this._status);
|
2456
|
}
|
2457
|
if (this._parent && !opts.onlySelf) {
|
2458
|
this._parent.updateValueAndValidity(opts);
|
2459
|
}
|
2460
|
}
|
2461
|
/**
|
2462
|
* \@internal
|
2463
|
* @param {?=} opts
|
2464
|
* @return {?}
|
2465
|
*/
|
2466
|
_updateTreeValidity(opts = { emitEvent: true }) {
|
2467
|
this._forEachChild((ctrl) => ctrl._updateTreeValidity(opts));
|
2468
|
this.updateValueAndValidity({ onlySelf: true, emitEvent: opts.emitEvent });
|
2469
|
}
|
2470
|
/**
|
2471
|
* @return {?}
|
2472
|
*/
|
2473
|
_setInitialStatus() { this._status = this._allControlsDisabled() ? DISABLED : VALID; }
|
2474
|
/**
|
2475
|
* @return {?}
|
2476
|
*/
|
2477
|
_runValidator() {
|
2478
|
return this.validator ? this.validator(this) : null;
|
2479
|
}
|
2480
|
/**
|
2481
|
* @param {?=} emitEvent
|
2482
|
* @return {?}
|
2483
|
*/
|
2484
|
_runAsyncValidator(emitEvent) {
|
2485
|
if (this.asyncValidator) {
|
2486
|
this._status = PENDING;
|
2487
|
const /** @type {?} */ obs = toObservable(this.asyncValidator(this));
|
2488
|
this._asyncValidationSubscription =
|
2489
|
obs.subscribe((errors) => this.setErrors(errors, { emitEvent }));
|
2490
|
}
|
2491
|
}
|
2492
|
/**
|
2493
|
* @return {?}
|
2494
|
*/
|
2495
|
_cancelExistingSubscription() {
|
2496
|
if (this._asyncValidationSubscription) {
|
2497
|
this._asyncValidationSubscription.unsubscribe();
|
2498
|
}
|
2499
|
}
|
2500
|
/**
|
2501
|
* Sets errors on a form control.
|
2502
|
*
|
2503
|
* This is used when validations are run manually by the user, rather than automatically.
|
2504
|
*
|
2505
|
* Calling `setErrors` will also update the validity of the parent control.
|
2506
|
*
|
2507
|
* ### Example
|
2508
|
*
|
2509
|
* ```
|
2510
|
* const login = new FormControl("someLogin");
|
2511
|
* login.setErrors({
|
2512
|
* "notUnique": true
|
2513
|
* });
|
2514
|
*
|
2515
|
* expect(login.valid).toEqual(false);
|
2516
|
* expect(login.errors).toEqual({"notUnique": true});
|
2517
|
*
|
2518
|
* login.setValue("someOtherLogin");
|
2519
|
*
|
2520
|
* expect(login.valid).toEqual(true);
|
2521
|
* ```
|
2522
|
* @param {?} errors
|
2523
|
* @param {?=} opts
|
2524
|
* @return {?}
|
2525
|
*/
|
2526
|
setErrors(errors, opts = {}) {
|
2527
|
this._errors = errors;
|
2528
|
this._updateControlsErrors(opts.emitEvent !== false);
|
2529
|
}
|
2530
|
/**
|
2531
|
* Retrieves a child control given the control's name or path.
|
2532
|
*
|
2533
|
* Paths can be passed in as an array or a string delimited by a dot.
|
2534
|
*
|
2535
|
* To get a control nested within a `person` sub-group:
|
2536
|
*
|
2537
|
* * `this.form.get('person.name');`
|
2538
|
*
|
2539
|
* -OR-
|
2540
|
*
|
2541
|
* * `this.form.get(['person', 'name']);`
|
2542
|
* @param {?} path
|
2543
|
* @return {?}
|
2544
|
*/
|
2545
|
get(path) { return _find(this, path, '.'); }
|
2546
|
/**
|
2547
|
* Returns error data if the control with the given path has the error specified. Otherwise
|
2548
|
* returns null or undefined.
|
2549
|
*
|
2550
|
* If no path is given, it checks for the error on the present control.
|
2551
|
* @param {?} errorCode
|
2552
|
* @param {?=} path
|
2553
|
* @return {?}
|
2554
|
*/
|
2555
|
getError(errorCode, path) {
|
2556
|
const /** @type {?} */ control = path ? this.get(path) : this;
|
2557
|
return control && control._errors ? control._errors[errorCode] : null;
|
2558
|
}
|
2559
|
/**
|
2560
|
* Returns true if the control with the given path has the error specified. Otherwise
|
2561
|
* returns false.
|
2562
|
*
|
2563
|
* If no path is given, it checks for the error on the present control.
|
2564
|
* @param {?} errorCode
|
2565
|
* @param {?=} path
|
2566
|
* @return {?}
|
2567
|
*/
|
2568
|
hasError(errorCode, path) { return !!this.getError(errorCode, path); }
|
2569
|
/**
|
2570
|
* Retrieves the top-level ancestor of this control.
|
2571
|
* @return {?}
|
2572
|
*/
|
2573
|
get root() {
|
2574
|
let /** @type {?} */ x = this;
|
2575
|
while (x._parent) {
|
2576
|
x = x._parent;
|
2577
|
}
|
2578
|
return x;
|
2579
|
}
|
2580
|
/**
|
2581
|
* \@internal
|
2582
|
* @param {?} emitEvent
|
2583
|
* @return {?}
|
2584
|
*/
|
2585
|
_updateControlsErrors(emitEvent) {
|
2586
|
this._status = this._calculateStatus();
|
2587
|
if (emitEvent) {
|
2588
|
this._statusChanges.emit(this._status);
|
2589
|
}
|
2590
|
if (this._parent) {
|
2591
|
this._parent._updateControlsErrors(emitEvent);
|
2592
|
}
|
2593
|
}
|
2594
|
/**
|
2595
|
* \@internal
|
2596
|
* @return {?}
|
2597
|
*/
|
2598
|
_initObservables() {
|
2599
|
this._valueChanges = new EventEmitter();
|
2600
|
this._statusChanges = new EventEmitter();
|
2601
|
}
|
2602
|
/**
|
2603
|
* @return {?}
|
2604
|
*/
|
2605
|
_calculateStatus() {
|
2606
|
if (this._allControlsDisabled())
|
2607
|
return DISABLED;
|
2608
|
if (this._errors)
|
2609
|
return INVALID;
|
2610
|
if (this._anyControlsHaveStatus(PENDING))
|
2611
|
return PENDING;
|
2612
|
if (this._anyControlsHaveStatus(INVALID))
|
2613
|
return INVALID;
|
2614
|
return VALID;
|
2615
|
}
|
2616
|
/**
|
2617
|
* \@internal
|
2618
|
* @abstract
|
2619
|
* @return {?}
|
2620
|
*/
|
2621
|
_updateValue() { }
|
2622
|
/**
|
2623
|
* \@internal
|
2624
|
* @abstract
|
2625
|
* @param {?} cb
|
2626
|
* @return {?}
|
2627
|
*/
|
2628
|
_forEachChild(cb) { }
|
2629
|
/**
|
2630
|
* \@internal
|
2631
|
* @abstract
|
2632
|
* @param {?} condition
|
2633
|
* @return {?}
|
2634
|
*/
|
2635
|
_anyControls(condition) { }
|
2636
|
/**
|
2637
|
* \@internal
|
2638
|
* @abstract
|
2639
|
* @return {?}
|
2640
|
*/
|
2641
|
_allControlsDisabled() { }
|
2642
|
/**
|
2643
|
* \@internal
|
2644
|
* @param {?} status
|
2645
|
* @return {?}
|
2646
|
*/
|
2647
|
_anyControlsHaveStatus(status) {
|
2648
|
return this._anyControls((control) => control.status === status);
|
2649
|
}
|
2650
|
/**
|
2651
|
* \@internal
|
2652
|
* @return {?}
|
2653
|
*/
|
2654
|
_anyControlsDirty() {
|
2655
|
return this._anyControls((control) => control.dirty);
|
2656
|
}
|
2657
|
/**
|
2658
|
* \@internal
|
2659
|
* @return {?}
|
2660
|
*/
|
2661
|
_anyControlsTouched() {
|
2662
|
return this._anyControls((control) => control.touched);
|
2663
|
}
|
2664
|
/**
|
2665
|
* \@internal
|
2666
|
* @param {?=} opts
|
2667
|
* @return {?}
|
2668
|
*/
|
2669
|
_updatePristine(opts = {}) {
|
2670
|
this._pristine = !this._anyControlsDirty();
|
2671
|
if (this._parent && !opts.onlySelf) {
|
2672
|
this._parent._updatePristine(opts);
|
2673
|
}
|
2674
|
}
|
2675
|
/**
|
2676
|
* \@internal
|
2677
|
* @param {?=} opts
|
2678
|
* @return {?}
|
2679
|
*/
|
2680
|
_updateTouched(opts = {}) {
|
2681
|
this._touched = this._anyControlsTouched();
|
2682
|
if (this._parent && !opts.onlySelf) {
|
2683
|
this._parent._updateTouched(opts);
|
2684
|
}
|
2685
|
}
|
2686
|
/**
|
2687
|
* \@internal
|
2688
|
* @param {?} formState
|
2689
|
* @return {?}
|
2690
|
*/
|
2691
|
_isBoxedValue(formState) {
|
2692
|
return typeof formState === 'object' && formState !== null &&
|
2693
|
Object.keys(formState).length === 2 && 'value' in formState && 'disabled' in formState;
|
2694
|
}
|
2695
|
/**
|
2696
|
* \@internal
|
2697
|
* @param {?} fn
|
2698
|
* @return {?}
|
2699
|
*/
|
2700
|
_registerOnCollectionChange(fn) { this._onCollectionChange = fn; }
|
2701
|
}
|
2702
|
/**
|
2703
|
* \@whatItDoes Tracks the value and validation status of an individual form control.
|
2704
|
*
|
2705
|
* It is one of the three fundamental building blocks of Angular forms, along with
|
2706
|
* {\@link FormGroup} and {\@link FormArray}.
|
2707
|
*
|
2708
|
* \@howToUse
|
2709
|
*
|
2710
|
* When instantiating a {\@link FormControl}, you can pass in an initial value as the
|
2711
|
* first argument. Example:
|
2712
|
*
|
2713
|
* ```ts
|
2714
|
* const ctrl = new FormControl('some value');
|
2715
|
* console.log(ctrl.value); // 'some value'
|
2716
|
* ```
|
2717
|
*
|
2718
|
* You can also initialize the control with a form state object on instantiation,
|
2719
|
* which includes both the value and whether or not the control is disabled.
|
2720
|
* You can't use the value key without the disabled key; both are required
|
2721
|
* to use this way of initialization.
|
2722
|
*
|
2723
|
* ```ts
|
2724
|
* const ctrl = new FormControl({value: 'n/a', disabled: true});
|
2725
|
* console.log(ctrl.value); // 'n/a'
|
2726
|
* console.log(ctrl.status); // 'DISABLED'
|
2727
|
* ```
|
2728
|
*
|
2729
|
* To include a sync validator (or an array of sync validators) with the control,
|
2730
|
* pass it in as the second argument. Async validators are also supported, but
|
2731
|
* have to be passed in separately as the third arg.
|
2732
|
*
|
2733
|
* ```ts
|
2734
|
* const ctrl = new FormControl('', Validators.required);
|
2735
|
* console.log(ctrl.value); // ''
|
2736
|
* console.log(ctrl.status); // 'INVALID'
|
2737
|
* ```
|
2738
|
*
|
2739
|
* See its superclass, {\@link AbstractControl}, for more properties and methods.
|
2740
|
*
|
2741
|
* * **npm package**: `\@angular/forms`
|
2742
|
*
|
2743
|
* \@stable
|
2744
|
*/
|
2745
|
class FormControl extends AbstractControl {
|
2746
|
/**
|
2747
|
* @param {?=} formState
|
2748
|
* @param {?=} validator
|
2749
|
* @param {?=} asyncValidator
|
2750
|
*/
|
2751
|
constructor(formState = null, validator, asyncValidator) {
|
2752
|
super(coerceToValidator(validator), coerceToAsyncValidator(asyncValidator));
|
2753
|
/**
|
2754
|
* \@internal
|
2755
|
*/
|
2756
|
this._onChange = [];
|
2757
|
this._applyFormState(formState);
|
2758
|
this.updateValueAndValidity({ onlySelf: true, emitEvent: false });
|
2759
|
this._initObservables();
|
2760
|
}
|
2761
|
/**
|
2762
|
* Set the value of the form control to `value`.
|
2763
|
*
|
2764
|
* If `onlySelf` is `true`, this change will only affect the validation of this `FormControl`
|
2765
|
* and not its parent component. This defaults to false.
|
2766
|
*
|
2767
|
* If `emitEvent` is `true`, this
|
2768
|
* change will cause a `valueChanges` event on the `FormControl` to be emitted. This defaults
|
2769
|
* to true (as it falls through to `updateValueAndValidity`).
|
2770
|
*
|
2771
|
* If `emitModelToViewChange` is `true`, the view will be notified about the new value
|
2772
|
* via an `onChange` event. This is the default behavior if `emitModelToViewChange` is not
|
2773
|
* specified.
|
2774
|
*
|
2775
|
* If `emitViewToModelChange` is `true`, an ngModelChange event will be fired to update the
|
2776
|
* model. This is the default behavior if `emitViewToModelChange` is not specified.
|
2777
|
* @param {?} value
|
2778
|
* @param {?=} options
|
2779
|
* @return {?}
|
2780
|
*/
|
2781
|
setValue(value, options = {}) {
|
2782
|
this._value = value;
|
2783
|
if (this._onChange.length && options.emitModelToViewChange !== false) {
|
2784
|
this._onChange.forEach((changeFn) => changeFn(this._value, options.emitViewToModelChange !== false));
|
2785
|
}
|
2786
|
this.updateValueAndValidity(options);
|
2787
|
}
|
2788
|
/**
|
2789
|
* Patches the value of a control.
|
2790
|
*
|
2791
|
* This function is functionally the same as {\@link FormControl#setValue} at this level.
|
2792
|
* It exists for symmetry with {\@link FormGroup#patchValue} on `FormGroups` and `FormArrays`,
|
2793
|
* where it does behave differently.
|
2794
|
* @param {?} value
|
2795
|
* @param {?=} options
|
2796
|
* @return {?}
|
2797
|
*/
|
2798
|
patchValue(value, options = {}) {
|
2799
|
this.setValue(value, options);
|
2800
|
}
|
2801
|
/**
|
2802
|
* Resets the form control. This means by default:
|
2803
|
*
|
2804
|
* * it is marked as `pristine`
|
2805
|
* * it is marked as `untouched`
|
2806
|
* * value is set to null
|
2807
|
*
|
2808
|
* You can also reset to a specific form state by passing through a standalone
|
2809
|
* value or a form state object that contains both a value and a disabled state
|
2810
|
* (these are the only two properties that cannot be calculated).
|
2811
|
*
|
2812
|
* Ex:
|
2813
|
*
|
2814
|
* ```ts
|
2815
|
* this.control.reset('Nancy');
|
2816
|
*
|
2817
|
* console.log(this.control.value); // 'Nancy'
|
2818
|
* ```
|
2819
|
*
|
2820
|
* OR
|
2821
|
*
|
2822
|
* ```
|
2823
|
* this.control.reset({value: 'Nancy', disabled: true});
|
2824
|
*
|
2825
|
* console.log(this.control.value); // 'Nancy'
|
2826
|
* console.log(this.control.status); // 'DISABLED'
|
2827
|
* ```
|
2828
|
* @param {?=} formState
|
2829
|
* @param {?=} options
|
2830
|
* @return {?}
|
2831
|
*/
|
2832
|
reset(formState = null, options = {}) {
|
2833
|
this._applyFormState(formState);
|
2834
|
this.markAsPristine(options);
|
2835
|
this.markAsUntouched(options);
|
2836
|
this.setValue(this._value, options);
|
2837
|
}
|
2838
|
/**
|
2839
|
* \@internal
|
2840
|
* @return {?}
|
2841
|
*/
|
2842
|
_updateValue() { }
|
2843
|
/**
|
2844
|
* \@internal
|
2845
|
* @param {?} condition
|
2846
|
* @return {?}
|
2847
|
*/
|
2848
|
_anyControls(condition) { return false; }
|
2849
|
/**
|
2850
|
* \@internal
|
2851
|
* @return {?}
|
2852
|
*/
|
2853
|
_allControlsDisabled() { return this.disabled; }
|
2854
|
/**
|
2855
|
* Register a listener for change events.
|
2856
|
* @param {?} fn
|
2857
|
* @return {?}
|
2858
|
*/
|
2859
|
registerOnChange(fn) { this._onChange.push(fn); }
|
2860
|
/**
|
2861
|
* \@internal
|
2862
|
* @return {?}
|
2863
|
*/
|
2864
|
_clearChangeFns() {
|
2865
|
this._onChange = [];
|
2866
|
this._onDisabledChange = [];
|
2867
|
this._onCollectionChange = () => { };
|
2868
|
}
|
2869
|
/**
|
2870
|
* Register a listener for disabled events.
|
2871
|
* @param {?} fn
|
2872
|
* @return {?}
|
2873
|
*/
|
2874
|
registerOnDisabledChange(fn) {
|
2875
|
this._onDisabledChange.push(fn);
|
2876
|
}
|
2877
|
/**
|
2878
|
* \@internal
|
2879
|
* @param {?} cb
|
2880
|
* @return {?}
|
2881
|
*/
|
2882
|
_forEachChild(cb) { }
|
2883
|
/**
|
2884
|
* @param {?} formState
|
2885
|
* @return {?}
|
2886
|
*/
|
2887
|
_applyFormState(formState) {
|
2888
|
if (this._isBoxedValue(formState)) {
|
2889
|
this._value = formState.value;
|
2890
|
formState.disabled ? this.disable({ onlySelf: true, emitEvent: false }) :
|
2891
|
this.enable({ onlySelf: true, emitEvent: false });
|
2892
|
}
|
2893
|
else {
|
2894
|
this._value = formState;
|
2895
|
}
|
2896
|
}
|
2897
|
}
|
2898
|
/**
|
2899
|
* \@whatItDoes Tracks the value and validity state of a group of {\@link FormControl}
|
2900
|
* instances.
|
2901
|
*
|
2902
|
* A `FormGroup` aggregates the values of each child {\@link FormControl} into one object,
|
2903
|
* with each control name as the key. It calculates its status by reducing the statuses
|
2904
|
* of its children. For example, if one of the controls in a group is invalid, the entire
|
2905
|
* group becomes invalid.
|
2906
|
*
|
2907
|
* `FormGroup` is one of the three fundamental building blocks used to define forms in Angular,
|
2908
|
* along with {\@link FormControl} and {\@link FormArray}.
|
2909
|
*
|
2910
|
* \@howToUse
|
2911
|
*
|
2912
|
* When instantiating a {\@link FormGroup}, pass in a collection of child controls as the first
|
2913
|
* argument. The key for each child will be the name under which it is registered.
|
2914
|
*
|
2915
|
* ### Example
|
2916
|
*
|
2917
|
* ```
|
2918
|
* const form = new FormGroup({
|
2919
|
* first: new FormControl('Nancy', Validators.minLength(2)),
|
2920
|
* last: new FormControl('Drew'),
|
2921
|
* });
|
2922
|
*
|
2923
|
* console.log(form.value); // {first: 'Nancy', last; 'Drew'}
|
2924
|
* console.log(form.status); // 'VALID'
|
2925
|
* ```
|
2926
|
*
|
2927
|
* You can also include group-level validators as the second arg, or group-level async
|
2928
|
* validators as the third arg. These come in handy when you want to perform validation
|
2929
|
* that considers the value of more than one child control.
|
2930
|
*
|
2931
|
* ### Example
|
2932
|
*
|
2933
|
* ```
|
2934
|
* const form = new FormGroup({
|
2935
|
* password: new FormControl('', Validators.minLength(2)),
|
2936
|
* passwordConfirm: new FormControl('', Validators.minLength(2)),
|
2937
|
* }, passwordMatchValidator);
|
2938
|
*
|
2939
|
*
|
2940
|
* function passwordMatchValidator(g: FormGroup) {
|
2941
|
* return g.get('password').value === g.get('passwordConfirm').value
|
2942
|
* ? null : {'mismatch': true};
|
2943
|
* }
|
2944
|
* ```
|
2945
|
*
|
2946
|
* * **npm package**: `\@angular/forms`
|
2947
|
*
|
2948
|
* \@stable
|
2949
|
*/
|
2950
|
class FormGroup extends AbstractControl {
|
2951
|
/**
|
2952
|
* @param {?} controls
|
2953
|
* @param {?=} validator
|
2954
|
* @param {?=} asyncValidator
|
2955
|
*/
|
2956
|
constructor(controls, validator, asyncValidator) {
|
2957
|
super(validator || null, asyncValidator || null);
|
2958
|
this.controls = controls;
|
2959
|
this._initObservables();
|
2960
|
this._setUpControls();
|
2961
|
this.updateValueAndValidity({ onlySelf: true, emitEvent: false });
|
2962
|
}
|
2963
|
/**
|
2964
|
* Registers a control with the group's list of controls.
|
2965
|
*
|
2966
|
* This method does not update value or validity of the control, so for
|
2967
|
* most cases you'll want to use {\@link FormGroup#addControl} instead.
|
2968
|
* @param {?} name
|
2969
|
* @param {?} control
|
2970
|
* @return {?}
|
2971
|
*/
|
2972
|
registerControl(name, control) {
|
2973
|
if (this.controls[name])
|
2974
|
return this.controls[name];
|
2975
|
this.controls[name] = control;
|
2976
|
control.setParent(this);
|
2977
|
control._registerOnCollectionChange(this._onCollectionChange);
|
2978
|
return control;
|
2979
|
}
|
2980
|
/**
|
2981
|
* Add a control to this group.
|
2982
|
* @param {?} name
|
2983
|
* @param {?} control
|
2984
|
* @return {?}
|
2985
|
*/
|
2986
|
addControl(name, control) {
|
2987
|
this.registerControl(name, control);
|
2988
|
this.updateValueAndValidity();
|
2989
|
this._onCollectionChange();
|
2990
|
}
|
2991
|
/**
|
2992
|
* Remove a control from this group.
|
2993
|
* @param {?} name
|
2994
|
* @return {?}
|
2995
|
*/
|
2996
|
removeControl(name) {
|
2997
|
if (this.controls[name])
|
2998
|
this.controls[name]._registerOnCollectionChange(() => { });
|
2999
|
delete (this.controls[name]);
|
3000
|
this.updateValueAndValidity();
|
3001
|
this._onCollectionChange();
|
3002
|
}
|
3003
|
/**
|
3004
|
* Replace an existing control.
|
3005
|
* @param {?} name
|
3006
|
* @param {?} control
|
3007
|
* @return {?}
|
3008
|
*/
|
3009
|
setControl(name, control) {
|
3010
|
if (this.controls[name])
|
3011
|
this.controls[name]._registerOnCollectionChange(() => { });
|
3012
|
delete (this.controls[name]);
|
3013
|
if (control)
|
3014
|
this.registerControl(name, control);
|
3015
|
this.updateValueAndValidity();
|
3016
|
this._onCollectionChange();
|
3017
|
}
|
3018
|
/**
|
3019
|
* Check whether there is an enabled control with the given name in the group.
|
3020
|
*
|
3021
|
* It will return false for disabled controls. If you'd like to check for
|
3022
|
* existence in the group only, use {\@link AbstractControl#get} instead.
|
3023
|
* @param {?} controlName
|
3024
|
* @return {?}
|
3025
|
*/
|
3026
|
contains(controlName) {
|
3027
|
return this.controls.hasOwnProperty(controlName) && this.controls[controlName].enabled;
|
3028
|
}
|
3029
|
/**
|
3030
|
* Sets the value of the {\@link FormGroup}. It accepts an object that matches
|
3031
|
* the structure of the group, with control names as keys.
|
3032
|
*
|
3033
|
* This method performs strict checks, so it will throw an error if you try
|
3034
|
* to set the value of a control that doesn't exist or if you exclude the
|
3035
|
* value of a control.
|
3036
|
*
|
3037
|
* ### Example
|
3038
|
*
|
3039
|
* ```
|
3040
|
* const form = new FormGroup({
|
3041
|
* first: new FormControl(),
|
3042
|
* last: new FormControl()
|
3043
|
* });
|
3044
|
* console.log(form.value); // {first: null, last: null}
|
3045
|
*
|
3046
|
* form.setValue({first: 'Nancy', last: 'Drew'});
|
3047
|
* console.log(form.value); // {first: 'Nancy', last: 'Drew'}
|
3048
|
*
|
3049
|
* ```
|
3050
|
* @param {?} value
|
3051
|
* @param {?=} options
|
3052
|
* @return {?}
|
3053
|
*/
|
3054
|
setValue(value, options = {}) {
|
3055
|
this._checkAllValuesPresent(value);
|
3056
|
Object.keys(value).forEach(name => {
|
3057
|
this._throwIfControlMissing(name);
|
3058
|
this.controls[name].setValue(value[name], { onlySelf: true, emitEvent: options.emitEvent });
|
3059
|
});
|
3060
|
this.updateValueAndValidity(options);
|
3061
|
}
|
3062
|
/**
|
3063
|
* Patches the value of the {\@link FormGroup}. It accepts an object with control
|
3064
|
* names as keys, and will do its best to match the values to the correct controls
|
3065
|
* in the group.
|
3066
|
*
|
3067
|
* It accepts both super-sets and sub-sets of the group without throwing an error.
|
3068
|
*
|
3069
|
* ### Example
|
3070
|
*
|
3071
|
* ```
|
3072
|
* const form = new FormGroup({
|
3073
|
* first: new FormControl(),
|
3074
|
* last: new FormControl()
|
3075
|
* });
|
3076
|
* console.log(form.value); // {first: null, last: null}
|
3077
|
*
|
3078
|
* form.patchValue({first: 'Nancy'});
|
3079
|
* console.log(form.value); // {first: 'Nancy', last: null}
|
3080
|
*
|
3081
|
* ```
|
3082
|
* @param {?} value
|
3083
|
* @param {?=} options
|
3084
|
* @return {?}
|
3085
|
*/
|
3086
|
patchValue(value, options = {}) {
|
3087
|
Object.keys(value).forEach(name => {
|
3088
|
if (this.controls[name]) {
|
3089
|
this.controls[name].patchValue(value[name], { onlySelf: true, emitEvent: options.emitEvent });
|
3090
|
}
|
3091
|
});
|
3092
|
this.updateValueAndValidity(options);
|
3093
|
}
|
3094
|
/**
|
3095
|
* Resets the {\@link FormGroup}. This means by default:
|
3096
|
*
|
3097
|
* * The group and all descendants are marked `pristine`
|
3098
|
* * The group and all descendants are marked `untouched`
|
3099
|
* * The value of all descendants will be null or null maps
|
3100
|
*
|
3101
|
* You can also reset to a specific form state by passing in a map of states
|
3102
|
* that matches the structure of your form, with control names as keys. The state
|
3103
|
* can be a standalone value or a form state object with both a value and a disabled
|
3104
|
* status.
|
3105
|
*
|
3106
|
* ### Example
|
3107
|
*
|
3108
|
* ```ts
|
3109
|
* this.form.reset({first: 'name', last: 'last name'});
|
3110
|
*
|
3111
|
* console.log(this.form.value); // {first: 'name', last: 'last name'}
|
3112
|
* ```
|
3113
|
*
|
3114
|
* - OR -
|
3115
|
*
|
3116
|
* ```
|
3117
|
* this.form.reset({
|
3118
|
* first: {value: 'name', disabled: true},
|
3119
|
* last: 'last'
|
3120
|
* });
|
3121
|
*
|
3122
|
* console.log(this.form.value); // {first: 'name', last: 'last name'}
|
3123
|
* console.log(this.form.get('first').status); // 'DISABLED'
|
3124
|
* ```
|
3125
|
* @param {?=} value
|
3126
|
* @param {?=} options
|
3127
|
* @return {?}
|
3128
|
*/
|
3129
|
reset(value = {}, options = {}) {
|
3130
|
this._forEachChild((control, name) => {
|
3131
|
control.reset(value[name], { onlySelf: true, emitEvent: options.emitEvent });
|
3132
|
});
|
3133
|
this.updateValueAndValidity(options);
|
3134
|
this._updatePristine(options);
|
3135
|
this._updateTouched(options);
|
3136
|
}
|
3137
|
/**
|
3138
|
* The aggregate value of the {\@link FormGroup}, including any disabled controls.
|
3139
|
*
|
3140
|
* If you'd like to include all values regardless of disabled status, use this method.
|
3141
|
* Otherwise, the `value` property is the best way to get the value of the group.
|
3142
|
* @return {?}
|
3143
|
*/
|
3144
|
getRawValue() {
|
3145
|
return this._reduceChildren({}, (acc, control, name) => {
|
3146
|
acc[name] = control instanceof FormControl ? control.value : ((control)).getRawValue();
|
3147
|
return acc;
|
3148
|
});
|
3149
|
}
|
3150
|
/**
|
3151
|
* \@internal
|
3152
|
* @param {?} name
|
3153
|
* @return {?}
|
3154
|
*/
|
3155
|
_throwIfControlMissing(name) {
|
3156
|
if (!Object.keys(this.controls).length) {
|
3157
|
throw new Error(`
|
3158
|
There are no form controls registered with this group yet. If you're using ngModel,
|
3159
|
you may want to check next tick (e.g. use setTimeout).
|
3160
|
`);
|
3161
|
}
|
3162
|
if (!this.controls[name]) {
|
3163
|
throw new Error(`Cannot find form control with name: ${name}.`);
|
3164
|
}
|
3165
|
}
|
3166
|
/**
|
3167
|
* \@internal
|
3168
|
* @param {?} cb
|
3169
|
* @return {?}
|
3170
|
*/
|
3171
|
_forEachChild(cb) {
|
3172
|
Object.keys(this.controls).forEach(k => cb(this.controls[k], k));
|
3173
|
}
|
3174
|
/**
|
3175
|
* \@internal
|
3176
|
* @return {?}
|
3177
|
*/
|
3178
|
_setUpControls() {
|
3179
|
this._forEachChild((control) => {
|
3180
|
control.setParent(this);
|
3181
|
control._registerOnCollectionChange(this._onCollectionChange);
|
3182
|
});
|
3183
|
}
|
3184
|
/**
|
3185
|
* \@internal
|
3186
|
* @return {?}
|
3187
|
*/
|
3188
|
_updateValue() { this._value = this._reduceValue(); }
|
3189
|
/**
|
3190
|
* \@internal
|
3191
|
* @param {?} condition
|
3192
|
* @return {?}
|
3193
|
*/
|
3194
|
_anyControls(condition) {
|
3195
|
let /** @type {?} */ res = false;
|
3196
|
this._forEachChild((control, name) => {
|
3197
|
res = res || (this.contains(name) && condition(control));
|
3198
|
});
|
3199
|
return res;
|
3200
|
}
|
3201
|
/**
|
3202
|
* \@internal
|
3203
|
* @return {?}
|
3204
|
*/
|
3205
|
_reduceValue() {
|
3206
|
return this._reduceChildren({}, (acc, control, name) => {
|
3207
|
if (control.enabled || this.disabled) {
|
3208
|
acc[name] = control.value;
|
3209
|
}
|
3210
|
return acc;
|
3211
|
});
|
3212
|
}
|
3213
|
/**
|
3214
|
* \@internal
|
3215
|
* @param {?} initValue
|
3216
|
* @param {?} fn
|
3217
|
* @return {?}
|
3218
|
*/
|
3219
|
_reduceChildren(initValue, fn) {
|
3220
|
let /** @type {?} */ res = initValue;
|
3221
|
this._forEachChild((control, name) => { res = fn(res, control, name); });
|
3222
|
return res;
|
3223
|
}
|
3224
|
/**
|
3225
|
* \@internal
|
3226
|
* @return {?}
|
3227
|
*/
|
3228
|
_allControlsDisabled() {
|
3229
|
for (const /** @type {?} */ controlName of Object.keys(this.controls)) {
|
3230
|
if (this.controls[controlName].enabled) {
|
3231
|
return false;
|
3232
|
}
|
3233
|
}
|
3234
|
return Object.keys(this.controls).length > 0 || this.disabled;
|
3235
|
}
|
3236
|
/**
|
3237
|
* \@internal
|
3238
|
* @param {?} value
|
3239
|
* @return {?}
|
3240
|
*/
|
3241
|
_checkAllValuesPresent(value) {
|
3242
|
this._forEachChild((control, name) => {
|
3243
|
if (value[name] === undefined) {
|
3244
|
throw new Error(`Must supply a value for form control with name: '${name}'.`);
|
3245
|
}
|
3246
|
});
|
3247
|
}
|
3248
|
}
|
3249
|
/**
|
3250
|
* \@whatItDoes Tracks the value and validity state of an array of {\@link FormControl},
|
3251
|
* {\@link FormGroup} or {\@link FormArray} instances.
|
3252
|
*
|
3253
|
* A `FormArray` aggregates the values of each child {\@link FormControl} into an array.
|
3254
|
* It calculates its status by reducing the statuses of its children. For example, if one of
|
3255
|
* the controls in a `FormArray` is invalid, the entire array becomes invalid.
|
3256
|
*
|
3257
|
* `FormArray` is one of the three fundamental building blocks used to define forms in Angular,
|
3258
|
* along with {\@link FormControl} and {\@link FormGroup}.
|
3259
|
*
|
3260
|
* \@howToUse
|
3261
|
*
|
3262
|
* When instantiating a {\@link FormArray}, pass in an array of child controls as the first
|
3263
|
* argument.
|
3264
|
*
|
3265
|
* ### Example
|
3266
|
*
|
3267
|
* ```
|
3268
|
* const arr = new FormArray([
|
3269
|
* new FormControl('Nancy', Validators.minLength(2)),
|
3270
|
* new FormControl('Drew'),
|
3271
|
* ]);
|
3272
|
*
|
3273
|
* console.log(arr.value); // ['Nancy', 'Drew']
|
3274
|
* console.log(arr.status); // 'VALID'
|
3275
|
* ```
|
3276
|
*
|
3277
|
* You can also include array-level validators as the second arg, or array-level async
|
3278
|
* validators as the third arg. These come in handy when you want to perform validation
|
3279
|
* that considers the value of more than one child control.
|
3280
|
*
|
3281
|
* ### Adding or removing controls
|
3282
|
*
|
3283
|
* To change the controls in the array, use the `push`, `insert`, or `removeAt` methods
|
3284
|
* in `FormArray` itself. These methods ensure the controls are properly tracked in the
|
3285
|
* form's hierarchy. Do not modify the array of `AbstractControl`s used to instantiate
|
3286
|
* the `FormArray` directly, as that will result in strange and unexpected behavior such
|
3287
|
* as broken change detection.
|
3288
|
*
|
3289
|
* * **npm package**: `\@angular/forms`
|
3290
|
*
|
3291
|
* \@stable
|
3292
|
*/
|
3293
|
class FormArray extends AbstractControl {
|
3294
|
/**
|
3295
|
* @param {?} controls
|
3296
|
* @param {?=} validator
|
3297
|
* @param {?=} asyncValidator
|
3298
|
*/
|
3299
|
constructor(controls, validator, asyncValidator) {
|
3300
|
super(validator || null, asyncValidator || null);
|
3301
|
this.controls = controls;
|
3302
|
this._initObservables();
|
3303
|
this._setUpControls();
|
3304
|
this.updateValueAndValidity({ onlySelf: true, emitEvent: false });
|
3305
|
}
|
3306
|
/**
|
3307
|
* Get the {\@link AbstractControl} at the given `index` in the array.
|
3308
|
* @param {?} index
|
3309
|
* @return {?}
|
3310
|
*/
|
3311
|
at(index) { return this.controls[index]; }
|
3312
|
/**
|
3313
|
* Insert a new {\@link AbstractControl} at the end of the array.
|
3314
|
* @param {?} control
|
3315
|
* @return {?}
|
3316
|
*/
|
3317
|
push(control) {
|
3318
|
this.controls.push(control);
|
3319
|
this._registerControl(control);
|
3320
|
this.updateValueAndValidity();
|
3321
|
this._onCollectionChange();
|
3322
|
}
|
3323
|
/**
|
3324
|
* Insert a new {\@link AbstractControl} at the given `index` in the array.
|
3325
|
* @param {?} index
|
3326
|
* @param {?} control
|
3327
|
* @return {?}
|
3328
|
*/
|
3329
|
insert(index, control) {
|
3330
|
this.controls.splice(index, 0, control);
|
3331
|
this._registerControl(control);
|
3332
|
this.updateValueAndValidity();
|
3333
|
this._onCollectionChange();
|
3334
|
}
|
3335
|
/**
|
3336
|
* Remove the control at the given `index` in the array.
|
3337
|
* @param {?} index
|
3338
|
* @return {?}
|
3339
|
*/
|
3340
|
removeAt(index) {
|
3341
|
if (this.controls[index])
|
3342
|
this.controls[index]._registerOnCollectionChange(() => { });
|
3343
|
this.controls.splice(index, 1);
|
3344
|
this.updateValueAndValidity();
|
3345
|
this._onCollectionChange();
|
3346
|
}
|
3347
|
/**
|
3348
|
* Replace an existing control.
|
3349
|
* @param {?} index
|
3350
|
* @param {?} control
|
3351
|
* @return {?}
|
3352
|
*/
|
3353
|
setControl(index, control) {
|
3354
|
if (this.controls[index])
|
3355
|
this.controls[index]._registerOnCollectionChange(() => { });
|
3356
|
this.controls.splice(index, 1);
|
3357
|
if (control) {
|
3358
|
this.controls.splice(index, 0, control);
|
3359
|
this._registerControl(control);
|
3360
|
}
|
3361
|
this.updateValueAndValidity();
|
3362
|
this._onCollectionChange();
|
3363
|
}
|
3364
|
/**
|
3365
|
* Length of the control array.
|
3366
|
* @return {?}
|
3367
|
*/
|
3368
|
get length() { return this.controls.length; }
|
3369
|
/**
|
3370
|
* Sets the value of the {\@link FormArray}. It accepts an array that matches
|
3371
|
* the structure of the control.
|
3372
|
*
|
3373
|
* This method performs strict checks, so it will throw an error if you try
|
3374
|
* to set the value of a control that doesn't exist or if you exclude the
|
3375
|
* value of a control.
|
3376
|
*
|
3377
|
* ### Example
|
3378
|
*
|
3379
|
* ```
|
3380
|
* const arr = new FormArray([
|
3381
|
* new FormControl(),
|
3382
|
* new FormControl()
|
3383
|
* ]);
|
3384
|
* console.log(arr.value); // [null, null]
|
3385
|
*
|
3386
|
* arr.setValue(['Nancy', 'Drew']);
|
3387
|
* console.log(arr.value); // ['Nancy', 'Drew']
|
3388
|
* ```
|
3389
|
* @param {?} value
|
3390
|
* @param {?=} options
|
3391
|
* @return {?}
|
3392
|
*/
|
3393
|
setValue(value, options = {}) {
|
3394
|
this._checkAllValuesPresent(value);
|
3395
|
value.forEach((newValue, index) => {
|
3396
|
this._throwIfControlMissing(index);
|
3397
|
this.at(index).setValue(newValue, { onlySelf: true, emitEvent: options.emitEvent });
|
3398
|
});
|
3399
|
this.updateValueAndValidity(options);
|
3400
|
}
|
3401
|
/**
|
3402
|
* Patches the value of the {\@link FormArray}. It accepts an array that matches the
|
3403
|
* structure of the control, and will do its best to match the values to the correct
|
3404
|
* controls in the group.
|
3405
|
*
|
3406
|
* It accepts both super-sets and sub-sets of the array without throwing an error.
|
3407
|
*
|
3408
|
* ### Example
|
3409
|
*
|
3410
|
* ```
|
3411
|
* const arr = new FormArray([
|
3412
|
* new FormControl(),
|
3413
|
* new FormControl()
|
3414
|
* ]);
|
3415
|
* console.log(arr.value); // [null, null]
|
3416
|
*
|
3417
|
* arr.patchValue(['Nancy']);
|
3418
|
* console.log(arr.value); // ['Nancy', null]
|
3419
|
* ```
|
3420
|
* @param {?} value
|
3421
|
* @param {?=} options
|
3422
|
* @return {?}
|
3423
|
*/
|
3424
|
patchValue(value, options = {}) {
|
3425
|
value.forEach((newValue, index) => {
|
3426
|
if (this.at(index)) {
|
3427
|
this.at(index).patchValue(newValue, { onlySelf: true, emitEvent: options.emitEvent });
|
3428
|
}
|
3429
|
});
|
3430
|
this.updateValueAndValidity(options);
|
3431
|
}
|
3432
|
/**
|
3433
|
* Resets the {\@link FormArray}. This means by default:
|
3434
|
*
|
3435
|
* * The array and all descendants are marked `pristine`
|
3436
|
* * The array and all descendants are marked `untouched`
|
3437
|
* * The value of all descendants will be null or null maps
|
3438
|
*
|
3439
|
* You can also reset to a specific form state by passing in an array of states
|
3440
|
* that matches the structure of the control. The state can be a standalone value
|
3441
|
* or a form state object with both a value and a disabled status.
|
3442
|
*
|
3443
|
* ### Example
|
3444
|
*
|
3445
|
* ```ts
|
3446
|
* this.arr.reset(['name', 'last name']);
|
3447
|
*
|
3448
|
* console.log(this.arr.value); // ['name', 'last name']
|
3449
|
* ```
|
3450
|
*
|
3451
|
* - OR -
|
3452
|
*
|
3453
|
* ```
|
3454
|
* this.arr.reset([
|
3455
|
* {value: 'name', disabled: true},
|
3456
|
* 'last'
|
3457
|
* ]);
|
3458
|
*
|
3459
|
* console.log(this.arr.value); // ['name', 'last name']
|
3460
|
* console.log(this.arr.get(0).status); // 'DISABLED'
|
3461
|
* ```
|
3462
|
* @param {?=} value
|
3463
|
* @param {?=} options
|
3464
|
* @return {?}
|
3465
|
*/
|
3466
|
reset(value = [], options = {}) {
|
3467
|
this._forEachChild((control, index) => {
|
3468
|
control.reset(value[index], { onlySelf: true, emitEvent: options.emitEvent });
|
3469
|
});
|
3470
|
this.updateValueAndValidity(options);
|
3471
|
this._updatePristine(options);
|
3472
|
this._updateTouched(options);
|
3473
|
}
|
3474
|
/**
|
3475
|
* The aggregate value of the array, including any disabled controls.
|
3476
|
*
|
3477
|
* If you'd like to include all values regardless of disabled status, use this method.
|
3478
|
* Otherwise, the `value` property is the best way to get the value of the array.
|
3479
|
* @return {?}
|
3480
|
*/
|
3481
|
getRawValue() {
|
3482
|
return this.controls.map((control) => {
|
3483
|
return control instanceof FormControl ? control.value : ((control)).getRawValue();
|
3484
|
});
|
3485
|
}
|
3486
|
/**
|
3487
|
* \@internal
|
3488
|
* @param {?} index
|
3489
|
* @return {?}
|
3490
|
*/
|
3491
|
_throwIfControlMissing(index) {
|
3492
|
if (!this.controls.length) {
|
3493
|
throw new Error(`
|
3494
|
There are no form controls registered with this array yet. If you're using ngModel,
|
3495
|
you may want to check next tick (e.g. use setTimeout).
|
3496
|
`);
|
3497
|
}
|
3498
|
if (!this.at(index)) {
|
3499
|
throw new Error(`Cannot find form control at index ${index}`);
|
3500
|
}
|
3501
|
}
|
3502
|
/**
|
3503
|
* \@internal
|
3504
|
* @param {?} cb
|
3505
|
* @return {?}
|
3506
|
*/
|
3507
|
_forEachChild(cb) {
|
3508
|
this.controls.forEach((control, index) => { cb(control, index); });
|
3509
|
}
|
3510
|
/**
|
3511
|
* \@internal
|
3512
|
* @return {?}
|
3513
|
*/
|
3514
|
_updateValue() {
|
3515
|
this._value = this.controls.filter((control) => control.enabled || this.disabled)
|
3516
|
.map((control) => control.value);
|
3517
|
}
|
3518
|
/**
|
3519
|
* \@internal
|
3520
|
* @param {?} condition
|
3521
|
* @return {?}
|
3522
|
*/
|
3523
|
_anyControls(condition) {
|
3524
|
return this.controls.some((control) => control.enabled && condition(control));
|
3525
|
}
|
3526
|
/**
|
3527
|
* \@internal
|
3528
|
* @return {?}
|
3529
|
*/
|
3530
|
_setUpControls() {
|
3531
|
this._forEachChild((control) => this._registerControl(control));
|
3532
|
}
|
3533
|
/**
|
3534
|
* \@internal
|
3535
|
* @param {?} value
|
3536
|
* @return {?}
|
3537
|
*/
|
3538
|
_checkAllValuesPresent(value) {
|
3539
|
this._forEachChild((control, i) => {
|
3540
|
if (value[i] === undefined) {
|
3541
|
throw new Error(`Must supply a value for form control at index: ${i}.`);
|
3542
|
}
|
3543
|
});
|
3544
|
}
|
3545
|
/**
|
3546
|
* \@internal
|
3547
|
* @return {?}
|
3548
|
*/
|
3549
|
_allControlsDisabled() {
|
3550
|
for (const /** @type {?} */ control of this.controls) {
|
3551
|
if (control.enabled)
|
3552
|
return false;
|
3553
|
}
|
3554
|
return this.controls.length > 0 || this.disabled;
|
3555
|
}
|
3556
|
/**
|
3557
|
* @param {?} control
|
3558
|
* @return {?}
|
3559
|
*/
|
3560
|
_registerControl(control) {
|
3561
|
control.setParent(this);
|
3562
|
control._registerOnCollectionChange(this._onCollectionChange);
|
3563
|
}
|
3564
|
}
|
3565
|
|
3566
|
/**
|
3567
|
* @license
|
3568
|
* Copyright Google Inc. All Rights Reserved.
|
3569
|
*
|
3570
|
* Use of this source code is governed by an MIT-style license that can be
|
3571
|
* found in the LICENSE file at https://angular.io/license
|
3572
|
*/
|
3573
|
const formDirectiveProvider = {
|
3574
|
provide: ControlContainer,
|
3575
|
useExisting: forwardRef(() => NgForm)
|
3576
|
};
|
3577
|
const resolvedPromise = Promise.resolve(null);
|
3578
|
/**
|
3579
|
* \@whatItDoes Creates a top-level {\@link FormGroup} instance and binds it to a form
|
3580
|
* to track aggregate form value and validation status.
|
3581
|
*
|
3582
|
* \@howToUse
|
3583
|
*
|
3584
|
* As soon as you import the `FormsModule`, this directive becomes active by default on
|
3585
|
* all `<form>` tags. You don't need to add a special selector.
|
3586
|
*
|
3587
|
* You can export the directive into a local template variable using `ngForm` as the key
|
3588
|
* (ex: `#myForm="ngForm"`). This is optional, but useful. Many properties from the underlying
|
3589
|
* {\@link FormGroup} instance are duplicated on the directive itself, so a reference to it
|
3590
|
* will give you access to the aggregate value and validity status of the form, as well as
|
3591
|
* user interaction properties like `dirty` and `touched`.
|
3592
|
*
|
3593
|
* To register child controls with the form, you'll want to use {\@link NgModel} with a
|
3594
|
* `name` attribute. You can also use {\@link NgModelGroup} if you'd like to create
|
3595
|
* sub-groups within the form.
|
3596
|
*
|
3597
|
* You can listen to the directive's `ngSubmit` event to be notified when the user has
|
3598
|
* triggered a form submission. The `ngSubmit` event will be emitted with the original form
|
3599
|
* submission event.
|
3600
|
*
|
3601
|
* In template driven forms, all `<form>` tags are automatically tagged as `NgForm`.
|
3602
|
* If you want to import the `FormsModule` but skip its usage in some forms,
|
3603
|
* for example, to use native HTML5 validation, you can add `ngNoForm` and the `<form>`
|
3604
|
* tags won't create an `NgForm` directive. In reactive forms, using `ngNoForm` is
|
3605
|
* unnecessary because the `<form>` tags are inert. In that case, you would
|
3606
|
* refrain from using the `formGroup` directive.
|
3607
|
*
|
3608
|
* {\@example forms/ts/simpleForm/simple_form_example.ts region='Component'}
|
3609
|
*
|
3610
|
* * **npm package**: `\@angular/forms`
|
3611
|
*
|
3612
|
* * **NgModule**: `FormsModule`
|
3613
|
*
|
3614
|
* \@stable
|
3615
|
*/
|
3616
|
class NgForm extends ControlContainer {
|
3617
|
/**
|
3618
|
* @param {?} validators
|
3619
|
* @param {?} asyncValidators
|
3620
|
*/
|
3621
|
constructor(validators, asyncValidators) {
|
3622
|
super();
|
3623
|
this._submitted = false;
|
3624
|
this.ngSubmit = new EventEmitter();
|
3625
|
this.form =
|
3626
|
new FormGroup({}, composeValidators(validators), composeAsyncValidators(asyncValidators));
|
3627
|
}
|
3628
|
/**
|
3629
|
* @return {?}
|
3630
|
*/
|
3631
|
get submitted() { return this._submitted; }
|
3632
|
/**
|
3633
|
* @return {?}
|
3634
|
*/
|
3635
|
get formDirective() { return this; }
|
3636
|
/**
|
3637
|
* @return {?}
|
3638
|
*/
|
3639
|
get control() { return this.form; }
|
3640
|
/**
|
3641
|
* @return {?}
|
3642
|
*/
|
3643
|
get path() { return []; }
|
3644
|
/**
|
3645
|
* @return {?}
|
3646
|
*/
|
3647
|
get controls() { return this.form.controls; }
|
3648
|
/**
|
3649
|
* @param {?} dir
|
3650
|
* @return {?}
|
3651
|
*/
|
3652
|
addControl(dir) {
|
3653
|
resolvedPromise.then(() => {
|
3654
|
const /** @type {?} */ container = this._findContainer(dir.path);
|
3655
|
dir._control = (container.registerControl(dir.name, dir.control));
|
3656
|
setUpControl(dir.control, dir);
|
3657
|
dir.control.updateValueAndValidity({ emitEvent: false });
|
3658
|
});
|
3659
|
}
|
3660
|
/**
|
3661
|
* @param {?} dir
|
3662
|
* @return {?}
|
3663
|
*/
|
3664
|
getControl(dir) { return (this.form.get(dir.path)); }
|
3665
|
/**
|
3666
|
* @param {?} dir
|
3667
|
* @return {?}
|
3668
|
*/
|
3669
|
removeControl(dir) {
|
3670
|
resolvedPromise.then(() => {
|
3671
|
const /** @type {?} */ container = this._findContainer(dir.path);
|
3672
|
if (container) {
|
3673
|
container.removeControl(dir.name);
|
3674
|
}
|
3675
|
});
|
3676
|
}
|
3677
|
/**
|
3678
|
* @param {?} dir
|
3679
|
* @return {?}
|
3680
|
*/
|
3681
|
addFormGroup(dir) {
|
3682
|
resolvedPromise.then(() => {
|
3683
|
const /** @type {?} */ container = this._findContainer(dir.path);
|
3684
|
const /** @type {?} */ group = new FormGroup({});
|
3685
|
setUpFormContainer(group, dir);
|
3686
|
container.registerControl(dir.name, group);
|
3687
|
group.updateValueAndValidity({ emitEvent: false });
|
3688
|
});
|
3689
|
}
|
3690
|
/**
|
3691
|
* @param {?} dir
|
3692
|
* @return {?}
|
3693
|
*/
|
3694
|
removeFormGroup(dir) {
|
3695
|
resolvedPromise.then(() => {
|
3696
|
const /** @type {?} */ container = this._findContainer(dir.path);
|
3697
|
if (container) {
|
3698
|
container.removeControl(dir.name);
|
3699
|
}
|
3700
|
});
|
3701
|
}
|
3702
|
/**
|
3703
|
* @param {?} dir
|
3704
|
* @return {?}
|
3705
|
*/
|
3706
|
getFormGroup(dir) { return (this.form.get(dir.path)); }
|
3707
|
/**
|
3708
|
* @param {?} dir
|
3709
|
* @param {?} value
|
3710
|
* @return {?}
|
3711
|
*/
|
3712
|
updateModel(dir, value) {
|
3713
|
resolvedPromise.then(() => {
|
3714
|
const /** @type {?} */ ctrl = (this.form.get(/** @type {?} */ ((dir.path))));
|
3715
|
ctrl.setValue(value);
|
3716
|
});
|
3717
|
}
|
3718
|
/**
|
3719
|
* @param {?} value
|
3720
|
* @return {?}
|
3721
|
*/
|
3722
|
setValue(value) { this.control.setValue(value); }
|
3723
|
/**
|
3724
|
* @param {?} $event
|
3725
|
* @return {?}
|
3726
|
*/
|
3727
|
onSubmit($event) {
|
3728
|
this._submitted = true;
|
3729
|
this.ngSubmit.emit($event);
|
3730
|
return false;
|
3731
|
}
|
3732
|
/**
|
3733
|
* @return {?}
|
3734
|
*/
|
3735
|
onReset() { this.resetForm(); }
|
3736
|
/**
|
3737
|
* @param {?=} value
|
3738
|
* @return {?}
|
3739
|
*/
|
3740
|
resetForm(value = undefined) {
|
3741
|
this.form.reset(value);
|
3742
|
this._submitted = false;
|
3743
|
}
|
3744
|
/**
|
3745
|
* \@internal
|
3746
|
* @param {?} path
|
3747
|
* @return {?}
|
3748
|
*/
|
3749
|
_findContainer(path) {
|
3750
|
path.pop();
|
3751
|
return path.length ? (this.form.get(path)) : this.form;
|
3752
|
}
|
3753
|
}
|
3754
|
NgForm.decorators = [
|
3755
|
{ type: Directive, args: [{
|
3756
|
selector: 'form:not([ngNoForm]):not([formGroup]),ngForm,[ngForm]',
|
3757
|
providers: [formDirectiveProvider],
|
3758
|
host: { '(submit)': 'onSubmit($event)', '(reset)': 'onReset()' },
|
3759
|
outputs: ['ngSubmit'],
|
3760
|
exportAs: 'ngForm'
|
3761
|
},] },
|
3762
|
];
|
3763
|
/**
|
3764
|
* @nocollapse
|
3765
|
*/
|
3766
|
NgForm.ctorParameters = () => [
|
3767
|
{ type: Array, decorators: [{ type: Optional }, { type: Self }, { type: Inject, args: [NG_VALIDATORS,] },] },
|
3768
|
{ type: Array, decorators: [{ type: Optional }, { type: Self }, { type: Inject, args: [NG_ASYNC_VALIDATORS,] },] },
|
3769
|
];
|
3770
|
|
3771
|
/**
|
3772
|
* @license
|
3773
|
* Copyright Google Inc. All Rights Reserved.
|
3774
|
*
|
3775
|
* Use of this source code is governed by an MIT-style license that can be
|
3776
|
* found in the LICENSE file at https://angular.io/license
|
3777
|
*/
|
3778
|
const FormErrorExamples = {
|
3779
|
formControlName: `
|
3780
|
<div [formGroup]="myGroup">
|
3781
|
<input formControlName="firstName">
|
3782
|
</div>
|
3783
|
|
3784
|
In your class:
|
3785
|
|
3786
|
this.myGroup = new FormGroup({
|
3787
|
firstName: new FormControl()
|
3788
|
});`,
|
3789
|
formGroupName: `
|
3790
|
<div [formGroup]="myGroup">
|
3791
|
<div formGroupName="person">
|
3792
|
<input formControlName="firstName">
|
3793
|
</div>
|
3794
|
</div>
|
3795
|
|
3796
|
In your class:
|
3797
|
|
3798
|
this.myGroup = new FormGroup({
|
3799
|
person: new FormGroup({ firstName: new FormControl() })
|
3800
|
});`,
|
3801
|
formArrayName: `
|
3802
|
<div [formGroup]="myGroup">
|
3803
|
<div formArrayName="cities">
|
3804
|
<div *ngFor="let city of cityArray.controls; index as i">
|
3805
|
<input [formControlName]="i">
|
3806
|
</div>
|
3807
|
</div>
|
3808
|
</div>
|
3809
|
|
3810
|
In your class:
|
3811
|
|
3812
|
this.cityArray = new FormArray([new FormControl('SF')]);
|
3813
|
this.myGroup = new FormGroup({
|
3814
|
cities: this.cityArray
|
3815
|
});`,
|
3816
|
ngModelGroup: `
|
3817
|
<form>
|
3818
|
<div ngModelGroup="person">
|
3819
|
<input [(ngModel)]="person.name" name="firstName">
|
3820
|
</div>
|
3821
|
</form>`,
|
3822
|
ngModelWithFormGroup: `
|
3823
|
<div [formGroup]="myGroup">
|
3824
|
<input formControlName="firstName">
|
3825
|
<input [(ngModel)]="showMoreControls" [ngModelOptions]="{standalone: true}">
|
3826
|
</div>
|
3827
|
`
|
3828
|
};
|
3829
|
|
3830
|
/**
|
3831
|
* @license
|
3832
|
* Copyright Google Inc. All Rights Reserved.
|
3833
|
*
|
3834
|
* Use of this source code is governed by an MIT-style license that can be
|
3835
|
* found in the LICENSE file at https://angular.io/license
|
3836
|
*/
|
3837
|
class TemplateDrivenErrors {
|
3838
|
/**
|
3839
|
* @return {?}
|
3840
|
*/
|
3841
|
static modelParentException() {
|
3842
|
throw new Error(`
|
3843
|
ngModel cannot be used to register form controls with a parent formGroup directive. Try using
|
3844
|
formGroup's partner directive "formControlName" instead. Example:
|
3845
|
|
3846
|
${FormErrorExamples.formControlName}
|
3847
|
|
3848
|
Or, if you'd like to avoid registering this form control, indicate that it's standalone in ngModelOptions:
|
3849
|
|
3850
|
Example:
|
3851
|
|
3852
|
${FormErrorExamples.ngModelWithFormGroup}`);
|
3853
|
}
|
3854
|
/**
|
3855
|
* @return {?}
|
3856
|
*/
|
3857
|
static formGroupNameException() {
|
3858
|
throw new Error(`
|
3859
|
ngModel cannot be used to register form controls with a parent formGroupName or formArrayName directive.
|
3860
|
|
3861
|
Option 1: Use formControlName instead of ngModel (reactive strategy):
|
3862
|
|
3863
|
${FormErrorExamples.formGroupName}
|
3864
|
|
3865
|
Option 2: Update ngModel's parent be ngModelGroup (template-driven strategy):
|
3866
|
|
3867
|
${FormErrorExamples.ngModelGroup}`);
|
3868
|
}
|
3869
|
/**
|
3870
|
* @return {?}
|
3871
|
*/
|
3872
|
static missingNameException() {
|
3873
|
throw new Error(`If ngModel is used within a form tag, either the name attribute must be set or the form
|
3874
|
control must be defined as 'standalone' in ngModelOptions.
|
3875
|
|
3876
|
Example 1: <input [(ngModel)]="person.firstName" name="first">
|
3877
|
Example 2: <input [(ngModel)]="person.firstName" [ngModelOptions]="{standalone: true}">`);
|
3878
|
}
|
3879
|
/**
|
3880
|
* @return {?}
|
3881
|
*/
|
3882
|
static modelGroupParentException() {
|
3883
|
throw new Error(`
|
3884
|
ngModelGroup cannot be used with a parent formGroup directive.
|
3885
|
|
3886
|
Option 1: Use formGroupName instead of ngModelGroup (reactive strategy):
|
3887
|
|
3888
|
${FormErrorExamples.formGroupName}
|
3889
|
|
3890
|
Option 2: Use a regular form tag instead of the formGroup directive (template-driven strategy):
|
3891
|
|
3892
|
${FormErrorExamples.ngModelGroup}`);
|
3893
|
}
|
3894
|
}
|
3895
|
|
3896
|
/**
|
3897
|
* @license
|
3898
|
* Copyright Google Inc. All Rights Reserved.
|
3899
|
*
|
3900
|
* Use of this source code is governed by an MIT-style license that can be
|
3901
|
* found in the LICENSE file at https://angular.io/license
|
3902
|
*/
|
3903
|
const modelGroupProvider = {
|
3904
|
provide: ControlContainer,
|
3905
|
useExisting: forwardRef(() => NgModelGroup)
|
3906
|
};
|
3907
|
/**
|
3908
|
* \@whatItDoes Creates and binds a {\@link FormGroup} instance to a DOM element.
|
3909
|
*
|
3910
|
* \@howToUse
|
3911
|
*
|
3912
|
* This directive can only be used as a child of {\@link NgForm} (or in other words,
|
3913
|
* within `<form>` tags).
|
3914
|
*
|
3915
|
* Use this directive if you'd like to create a sub-group within a form. This can
|
3916
|
* come in handy if you want to validate a sub-group of your form separately from
|
3917
|
* the rest of your form, or if some values in your domain model make more sense to
|
3918
|
* consume together in a nested object.
|
3919
|
*
|
3920
|
* Pass in the name you'd like this sub-group to have and it will become the key
|
3921
|
* for the sub-group in the form's full value. You can also export the directive into
|
3922
|
* a local template variable using `ngModelGroup` (ex: `#myGroup="ngModelGroup"`).
|
3923
|
*
|
3924
|
* {\@example forms/ts/ngModelGroup/ng_model_group_example.ts region='Component'}
|
3925
|
*
|
3926
|
* * **npm package**: `\@angular/forms`
|
3927
|
*
|
3928
|
* * **NgModule**: `FormsModule`
|
3929
|
*
|
3930
|
* \@stable
|
3931
|
*/
|
3932
|
class NgModelGroup extends AbstractFormGroupDirective {
|
3933
|
/**
|
3934
|
* @param {?} parent
|
3935
|
* @param {?} validators
|
3936
|
* @param {?} asyncValidators
|
3937
|
*/
|
3938
|
constructor(parent, validators, asyncValidators) {
|
3939
|
super();
|
3940
|
this._parent = parent;
|
3941
|
this._validators = validators;
|
3942
|
this._asyncValidators = asyncValidators;
|
3943
|
}
|
3944
|
/**
|
3945
|
* \@internal
|
3946
|
* @return {?}
|
3947
|
*/
|
3948
|
_checkParentType() {
|
3949
|
if (!(this._parent instanceof NgModelGroup) && !(this._parent instanceof NgForm)) {
|
3950
|
TemplateDrivenErrors.modelGroupParentException();
|
3951
|
}
|
3952
|
}
|
3953
|
}
|
3954
|
NgModelGroup.decorators = [
|
3955
|
{ type: Directive, args: [{ selector: '[ngModelGroup]', providers: [modelGroupProvider], exportAs: 'ngModelGroup' },] },
|
3956
|
];
|
3957
|
/**
|
3958
|
* @nocollapse
|
3959
|
*/
|
3960
|
NgModelGroup.ctorParameters = () => [
|
3961
|
{ type: ControlContainer, decorators: [{ type: Host }, { type: SkipSelf },] },
|
3962
|
{ type: Array, decorators: [{ type: Optional }, { type: Self }, { type: Inject, args: [NG_VALIDATORS,] },] },
|
3963
|
{ type: Array, decorators: [{ type: Optional }, { type: Self }, { type: Inject, args: [NG_ASYNC_VALIDATORS,] },] },
|
3964
|
];
|
3965
|
NgModelGroup.propDecorators = {
|
3966
|
'name': [{ type: Input, args: ['ngModelGroup',] },],
|
3967
|
};
|
3968
|
|
3969
|
/**
|
3970
|
* @license
|
3971
|
* Copyright Google Inc. All Rights Reserved.
|
3972
|
*
|
3973
|
* Use of this source code is governed by an MIT-style license that can be
|
3974
|
* found in the LICENSE file at https://angular.io/license
|
3975
|
*/
|
3976
|
const formControlBinding = {
|
3977
|
provide: NgControl,
|
3978
|
useExisting: forwardRef(() => NgModel)
|
3979
|
};
|
3980
|
/**
|
3981
|
* `ngModel` forces an additional change detection run when its inputs change:
|
3982
|
* E.g.:
|
3983
|
* ```
|
3984
|
* <div>{{myModel.valid}}</div>
|
3985
|
* <input [(ngModel)]="myValue" #myModel="ngModel">
|
3986
|
* ```
|
3987
|
* I.e. `ngModel` can export itself on the element and then be used in the template.
|
3988
|
* Normally, this would result in expressions before the `input` that use the exported directive
|
3989
|
* to have and old value as they have been
|
3990
|
* dirty checked before. As this is a very common case for `ngModel`, we added this second change
|
3991
|
* detection run.
|
3992
|
*
|
3993
|
* Notes:
|
3994
|
* - this is just one extra run no matter how many `ngModel` have been changed.
|
3995
|
* - this is a general problem when using `exportAs` for directives!
|
3996
|
*/
|
3997
|
const resolvedPromise$1 = Promise.resolve(null);
|
3998
|
/**
|
3999
|
* \@whatItDoes Creates a {\@link FormControl} instance from a domain model and binds it
|
4000
|
* to a form control element.
|
4001
|
*
|
4002
|
* The {\@link FormControl} instance will track the value, user interaction, and
|
4003
|
* validation status of the control and keep the view synced with the model. If used
|
4004
|
* within a parent form, the directive will also register itself with the form as a child
|
4005
|
* control.
|
4006
|
*
|
4007
|
* \@howToUse
|
4008
|
*
|
4009
|
* This directive can be used by itself or as part of a larger form. All you need is the
|
4010
|
* `ngModel` selector to activate it.
|
4011
|
*
|
4012
|
* It accepts a domain model as an optional {\@link Input}. If you have a one-way binding
|
4013
|
* to `ngModel` with `[]` syntax, changing the value of the domain model in the component
|
4014
|
* class will set the value in the view. If you have a two-way binding with `[()]` syntax
|
4015
|
* (also known as 'banana-box syntax'), the value in the UI will always be synced back to
|
4016
|
* the domain model in your class as well.
|
4017
|
*
|
4018
|
* If you wish to inspect the properties of the associated {\@link FormControl} (like
|
4019
|
* validity state), you can also export the directive into a local template variable using
|
4020
|
* `ngModel` as the key (ex: `#myVar="ngModel"`). You can then access the control using the
|
4021
|
* directive's `control` property, but most properties you'll need (like `valid` and `dirty`)
|
4022
|
* will fall through to the control anyway, so you can access them directly. You can see a
|
4023
|
* full list of properties directly available in {\@link AbstractControlDirective}.
|
4024
|
*
|
4025
|
* The following is an example of a simple standalone control using `ngModel`:
|
4026
|
*
|
4027
|
* {\@example forms/ts/simpleNgModel/simple_ng_model_example.ts region='Component'}
|
4028
|
*
|
4029
|
* When using the `ngModel` within `<form>` tags, you'll also need to supply a `name` attribute
|
4030
|
* so that the control can be registered with the parent form under that name.
|
4031
|
*
|
4032
|
* It's worth noting that in the context of a parent form, you often can skip one-way or
|
4033
|
* two-way binding because the parent form will sync the value for you. You can access
|
4034
|
* its properties by exporting it into a local template variable using `ngForm` (ex:
|
4035
|
* `#f="ngForm"`). Then you can pass it where it needs to go on submit.
|
4036
|
*
|
4037
|
* If you do need to populate initial values into your form, using a one-way binding for
|
4038
|
* `ngModel` tends to be sufficient as long as you use the exported form's value rather
|
4039
|
* than the domain model's value on submit.
|
4040
|
*
|
4041
|
* Take a look at an example of using `ngModel` within a form:
|
4042
|
*
|
4043
|
* {\@example forms/ts/simpleForm/simple_form_example.ts region='Component'}
|
4044
|
*
|
4045
|
* To see `ngModel` examples with different form control types, see:
|
4046
|
*
|
4047
|
* * Radio buttons: {\@link RadioControlValueAccessor}
|
4048
|
* * Selects: {\@link SelectControlValueAccessor}
|
4049
|
*
|
4050
|
* **npm package**: `\@angular/forms`
|
4051
|
*
|
4052
|
* **NgModule**: `FormsModule`
|
4053
|
*
|
4054
|
* \@stable
|
4055
|
*/
|
4056
|
class NgModel extends NgControl {
|
4057
|
/**
|
4058
|
* @param {?} parent
|
4059
|
* @param {?} validators
|
4060
|
* @param {?} asyncValidators
|
4061
|
* @param {?} valueAccessors
|
4062
|
*/
|
4063
|
constructor(parent, validators, asyncValidators, valueAccessors) {
|
4064
|
super();
|
4065
|
/**
|
4066
|
* \@internal
|
4067
|
*/
|
4068
|
this._control = new FormControl();
|
4069
|
/**
|
4070
|
* \@internal
|
4071
|
*/
|
4072
|
this._registered = false;
|
4073
|
this.update = new EventEmitter();
|
4074
|
this._parent = parent;
|
4075
|
this._rawValidators = validators || [];
|
4076
|
this._rawAsyncValidators = asyncValidators || [];
|
4077
|
this.valueAccessor = selectValueAccessor(this, valueAccessors);
|
4078
|
}
|
4079
|
/**
|
4080
|
* @param {?} changes
|
4081
|
* @return {?}
|
4082
|
*/
|
4083
|
ngOnChanges(changes) {
|
4084
|
this._checkForErrors();
|
4085
|
if (!this._registered)
|
4086
|
this._setUpControl();
|
4087
|
if ('isDisabled' in changes) {
|
4088
|
this._updateDisabled(changes);
|
4089
|
}
|
4090
|
if (isPropertyUpdated(changes, this.viewModel)) {
|
4091
|
this._updateValue(this.model);
|
4092
|
this.viewModel = this.model;
|
4093
|
}
|
4094
|
}
|
4095
|
/**
|
4096
|
* @return {?}
|
4097
|
*/
|
4098
|
ngOnDestroy() { this.formDirective && this.formDirective.removeControl(this); }
|
4099
|
/**
|
4100
|
* @return {?}
|
4101
|
*/
|
4102
|
get control() { return this._control; }
|
4103
|
/**
|
4104
|
* @return {?}
|
4105
|
*/
|
4106
|
get path() {
|
4107
|
return this._parent ? controlPath(this.name, this._parent) : [this.name];
|
4108
|
}
|
4109
|
/**
|
4110
|
* @return {?}
|
4111
|
*/
|
4112
|
get formDirective() { return this._parent ? this._parent.formDirective : null; }
|
4113
|
/**
|
4114
|
* @return {?}
|
4115
|
*/
|
4116
|
get validator() { return composeValidators(this._rawValidators); }
|
4117
|
/**
|
4118
|
* @return {?}
|
4119
|
*/
|
4120
|
get asyncValidator() {
|
4121
|
return composeAsyncValidators(this._rawAsyncValidators);
|
4122
|
}
|
4123
|
/**
|
4124
|
* @param {?} newValue
|
4125
|
* @return {?}
|
4126
|
*/
|
4127
|
viewToModelUpdate(newValue) {
|
4128
|
this.viewModel = newValue;
|
4129
|
this.update.emit(newValue);
|
4130
|
}
|
4131
|
/**
|
4132
|
* @return {?}
|
4133
|
*/
|
4134
|
_setUpControl() {
|
4135
|
this._isStandalone() ? this._setUpStandalone() :
|
4136
|
this.formDirective.addControl(this);
|
4137
|
this._registered = true;
|
4138
|
}
|
4139
|
/**
|
4140
|
* @return {?}
|
4141
|
*/
|
4142
|
_isStandalone() {
|
4143
|
return !this._parent || !!(this.options && this.options.standalone);
|
4144
|
}
|
4145
|
/**
|
4146
|
* @return {?}
|
4147
|
*/
|
4148
|
_setUpStandalone() {
|
4149
|
setUpControl(this._control, this);
|
4150
|
this._control.updateValueAndValidity({ emitEvent: false });
|
4151
|
}
|
4152
|
/**
|
4153
|
* @return {?}
|
4154
|
*/
|
4155
|
_checkForErrors() {
|
4156
|
if (!this._isStandalone()) {
|
4157
|
this._checkParentType();
|
4158
|
}
|
4159
|
this._checkName();
|
4160
|
}
|
4161
|
/**
|
4162
|
* @return {?}
|
4163
|
*/
|
4164
|
_checkParentType() {
|
4165
|
if (!(this._parent instanceof NgModelGroup) &&
|
4166
|
this._parent instanceof AbstractFormGroupDirective) {
|
4167
|
TemplateDrivenErrors.formGroupNameException();
|
4168
|
}
|
4169
|
else if (!(this._parent instanceof NgModelGroup) && !(this._parent instanceof NgForm)) {
|
4170
|
TemplateDrivenErrors.modelParentException();
|
4171
|
}
|
4172
|
}
|
4173
|
/**
|
4174
|
* @return {?}
|
4175
|
*/
|
4176
|
_checkName() {
|
4177
|
if (this.options && this.options.name)
|
4178
|
this.name = this.options.name;
|
4179
|
if (!this._isStandalone() && !this.name) {
|
4180
|
TemplateDrivenErrors.missingNameException();
|
4181
|
}
|
4182
|
}
|
4183
|
/**
|
4184
|
* @param {?} value
|
4185
|
* @return {?}
|
4186
|
*/
|
4187
|
_updateValue(value) {
|
4188
|
resolvedPromise$1.then(() => { this.control.setValue(value, { emitViewToModelChange: false }); });
|
4189
|
}
|
4190
|
/**
|
4191
|
* @param {?} changes
|
4192
|
* @return {?}
|
4193
|
*/
|
4194
|
_updateDisabled(changes) {
|
4195
|
const /** @type {?} */ disabledValue = changes['isDisabled'].currentValue;
|
4196
|
const /** @type {?} */ isDisabled = disabledValue === '' || (disabledValue && disabledValue !== 'false');
|
4197
|
resolvedPromise$1.then(() => {
|
4198
|
if (isDisabled && !this.control.disabled) {
|
4199
|
this.control.disable();
|
4200
|
}
|
4201
|
else if (!isDisabled && this.control.disabled) {
|
4202
|
this.control.enable();
|
4203
|
}
|
4204
|
});
|
4205
|
}
|
4206
|
}
|
4207
|
NgModel.decorators = [
|
4208
|
{ type: Directive, args: [{
|
4209
|
selector: '[ngModel]:not([formControlName]):not([formControl])',
|
4210
|
providers: [formControlBinding],
|
4211
|
exportAs: 'ngModel'
|
4212
|
},] },
|
4213
|
];
|
4214
|
/**
|
4215
|
* @nocollapse
|
4216
|
*/
|
4217
|
NgModel.ctorParameters = () => [
|
4218
|
{ type: ControlContainer, decorators: [{ type: Optional }, { type: Host },] },
|
4219
|
{ type: Array, decorators: [{ type: Optional }, { type: Self }, { type: Inject, args: [NG_VALIDATORS,] },] },
|
4220
|
{ type: Array, decorators: [{ type: Optional }, { type: Self }, { type: Inject, args: [NG_ASYNC_VALIDATORS,] },] },
|
4221
|
{ type: Array, decorators: [{ type: Optional }, { type: Self }, { type: Inject, args: [NG_VALUE_ACCESSOR,] },] },
|
4222
|
];
|
4223
|
NgModel.propDecorators = {
|
4224
|
'name': [{ type: Input },],
|
4225
|
'isDisabled': [{ type: Input, args: ['disabled',] },],
|
4226
|
'model': [{ type: Input, args: ['ngModel',] },],
|
4227
|
'options': [{ type: Input, args: ['ngModelOptions',] },],
|
4228
|
'update': [{ type: Output, args: ['ngModelChange',] },],
|
4229
|
};
|
4230
|
|
4231
|
/**
|
4232
|
* @license
|
4233
|
* Copyright Google Inc. All Rights Reserved.
|
4234
|
*
|
4235
|
* Use of this source code is governed by an MIT-style license that can be
|
4236
|
* found in the LICENSE file at https://angular.io/license
|
4237
|
*/
|
4238
|
class ReactiveErrors {
|
4239
|
/**
|
4240
|
* @return {?}
|
4241
|
*/
|
4242
|
static controlParentException() {
|
4243
|
throw new Error(`formControlName must be used with a parent formGroup directive. You'll want to add a formGroup
|
4244
|
directive and pass it an existing FormGroup instance (you can create one in your class).
|
4245
|
|
4246
|
Example:
|
4247
|
|
4248
|
${FormErrorExamples.formControlName}`);
|
4249
|
}
|
4250
|
/**
|
4251
|
* @return {?}
|
4252
|
*/
|
4253
|
static ngModelGroupException() {
|
4254
|
throw new Error(`formControlName cannot be used with an ngModelGroup parent. It is only compatible with parents
|
4255
|
that also have a "form" prefix: formGroupName, formArrayName, or formGroup.
|
4256
|
|
4257
|
Option 1: Update the parent to be formGroupName (reactive form strategy)
|
4258
|
|
4259
|
${FormErrorExamples.formGroupName}
|
4260
|
|
4261
|
Option 2: Use ngModel instead of formControlName (template-driven strategy)
|
4262
|
|
4263
|
${FormErrorExamples.ngModelGroup}`);
|
4264
|
}
|
4265
|
/**
|
4266
|
* @return {?}
|
4267
|
*/
|
4268
|
static missingFormException() {
|
4269
|
throw new Error(`formGroup expects a FormGroup instance. Please pass one in.
|
4270
|
|
4271
|
Example:
|
4272
|
|
4273
|
${FormErrorExamples.formControlName}`);
|
4274
|
}
|
4275
|
/**
|
4276
|
* @return {?}
|
4277
|
*/
|
4278
|
static groupParentException() {
|
4279
|
throw new Error(`formGroupName must be used with a parent formGroup directive. You'll want to add a formGroup
|
4280
|
directive and pass it an existing FormGroup instance (you can create one in your class).
|
4281
|
|
4282
|
Example:
|
4283
|
|
4284
|
${FormErrorExamples.formGroupName}`);
|
4285
|
}
|
4286
|
/**
|
4287
|
* @return {?}
|
4288
|
*/
|
4289
|
static arrayParentException() {
|
4290
|
throw new Error(`formArrayName must be used with a parent formGroup directive. You'll want to add a formGroup
|
4291
|
directive and pass it an existing FormGroup instance (you can create one in your class).
|
4292
|
|
4293
|
Example:
|
4294
|
|
4295
|
${FormErrorExamples.formArrayName}`);
|
4296
|
}
|
4297
|
/**
|
4298
|
* @return {?}
|
4299
|
*/
|
4300
|
static disabledAttrWarning() {
|
4301
|
console.warn(`
|
4302
|
It looks like you're using the disabled attribute with a reactive form directive. If you set disabled to true
|
4303
|
when you set up this control in your component class, the disabled attribute will actually be set in the DOM for
|
4304
|
you. We recommend using this approach to avoid 'changed after checked' errors.
|
4305
|
|
4306
|
Example:
|
4307
|
form = new FormGroup({
|
4308
|
first: new FormControl({value: 'Nancy', disabled: true}, Validators.required),
|
4309
|
last: new FormControl('Drew', Validators.required)
|
4310
|
});
|
4311
|
`);
|
4312
|
}
|
4313
|
}
|
4314
|
|
4315
|
/**
|
4316
|
* @license
|
4317
|
* Copyright Google Inc. All Rights Reserved.
|
4318
|
*
|
4319
|
* Use of this source code is governed by an MIT-style license that can be
|
4320
|
* found in the LICENSE file at https://angular.io/license
|
4321
|
*/
|
4322
|
const formControlBinding$1 = {
|
4323
|
provide: NgControl,
|
4324
|
useExisting: forwardRef(() => FormControlDirective)
|
4325
|
};
|
4326
|
/**
|
4327
|
* \@whatItDoes Syncs a standalone {\@link FormControl} instance to a form control element.
|
4328
|
*
|
4329
|
* In other words, this directive ensures that any values written to the {\@link FormControl}
|
4330
|
* instance programmatically will be written to the DOM element (model -> view). Conversely,
|
4331
|
* any values written to the DOM element through user input will be reflected in the
|
4332
|
* {\@link FormControl} instance (view -> model).
|
4333
|
*
|
4334
|
* \@howToUse
|
4335
|
*
|
4336
|
* Use this directive if you'd like to create and manage a {\@link FormControl} instance directly.
|
4337
|
* Simply create a {\@link FormControl}, save it to your component class, and pass it into the
|
4338
|
* {\@link FormControlDirective}.
|
4339
|
*
|
4340
|
* This directive is designed to be used as a standalone control. Unlike {\@link FormControlName},
|
4341
|
* it does not require that your {\@link FormControl} instance be part of any parent
|
4342
|
* {\@link FormGroup}, and it won't be registered to any {\@link FormGroupDirective} that
|
4343
|
* exists above it.
|
4344
|
*
|
4345
|
* **Get the value**: the `value` property is always synced and available on the
|
4346
|
* {\@link FormControl} instance. See a full list of available properties in
|
4347
|
* {\@link AbstractControl}.
|
4348
|
*
|
4349
|
* **Set the value**: You can pass in an initial value when instantiating the {\@link FormControl},
|
4350
|
* or you can set it programmatically later using {\@link AbstractControl#setValue setValue} or
|
4351
|
* {\@link AbstractControl#patchValue patchValue}.
|
4352
|
*
|
4353
|
* **Listen to value**: If you want to listen to changes in the value of the control, you can
|
4354
|
* subscribe to the {\@link AbstractControl#valueChanges valueChanges} event. You can also listen to
|
4355
|
* {\@link AbstractControl#statusChanges statusChanges} to be notified when the validation status is
|
4356
|
* re-calculated.
|
4357
|
*
|
4358
|
* ### Example
|
4359
|
*
|
4360
|
* {\@example forms/ts/simpleFormControl/simple_form_control_example.ts region='Component'}
|
4361
|
*
|
4362
|
* * **npm package**: `\@angular/forms`
|
4363
|
*
|
4364
|
* * **NgModule**: `ReactiveFormsModule`
|
4365
|
*
|
4366
|
* \@stable
|
4367
|
*/
|
4368
|
class FormControlDirective extends NgControl {
|
4369
|
/**
|
4370
|
* @param {?} validators
|
4371
|
* @param {?} asyncValidators
|
4372
|
* @param {?} valueAccessors
|
4373
|
*/
|
4374
|
constructor(validators, asyncValidators, valueAccessors) {
|
4375
|
super();
|
4376
|
this.update = new EventEmitter();
|
4377
|
this._rawValidators = validators || [];
|
4378
|
this._rawAsyncValidators = asyncValidators || [];
|
4379
|
this.valueAccessor = selectValueAccessor(this, valueAccessors);
|
4380
|
}
|
4381
|
/**
|
4382
|
* @param {?} isDisabled
|
4383
|
* @return {?}
|
4384
|
*/
|
4385
|
set isDisabled(isDisabled) { ReactiveErrors.disabledAttrWarning(); }
|
4386
|
/**
|
4387
|
* @param {?} changes
|
4388
|
* @return {?}
|
4389
|
*/
|
4390
|
ngOnChanges(changes) {
|
4391
|
if (this._isControlChanged(changes)) {
|
4392
|
setUpControl(this.form, this);
|
4393
|
if (this.control.disabled && ((this.valueAccessor)).setDisabledState) {
|
4394
|
((((this.valueAccessor)).setDisabledState))(true);
|
4395
|
}
|
4396
|
this.form.updateValueAndValidity({ emitEvent: false });
|
4397
|
}
|
4398
|
if (isPropertyUpdated(changes, this.viewModel)) {
|
4399
|
this.form.setValue(this.model);
|
4400
|
this.viewModel = this.model;
|
4401
|
}
|
4402
|
}
|
4403
|
/**
|
4404
|
* @return {?}
|
4405
|
*/
|
4406
|
get path() { return []; }
|
4407
|
/**
|
4408
|
* @return {?}
|
4409
|
*/
|
4410
|
get validator() { return composeValidators(this._rawValidators); }
|
4411
|
/**
|
4412
|
* @return {?}
|
4413
|
*/
|
4414
|
get asyncValidator() {
|
4415
|
return composeAsyncValidators(this._rawAsyncValidators);
|
4416
|
}
|
4417
|
/**
|
4418
|
* @return {?}
|
4419
|
*/
|
4420
|
get control() { return this.form; }
|
4421
|
/**
|
4422
|
* @param {?} newValue
|
4423
|
* @return {?}
|
4424
|
*/
|
4425
|
viewToModelUpdate(newValue) {
|
4426
|
this.viewModel = newValue;
|
4427
|
this.update.emit(newValue);
|
4428
|
}
|
4429
|
/**
|
4430
|
* @param {?} changes
|
4431
|
* @return {?}
|
4432
|
*/
|
4433
|
_isControlChanged(changes) {
|
4434
|
return changes.hasOwnProperty('form');
|
4435
|
}
|
4436
|
}
|
4437
|
FormControlDirective.decorators = [
|
4438
|
{ type: Directive, args: [{ selector: '[formControl]', providers: [formControlBinding$1], exportAs: 'ngForm' },] },
|
4439
|
];
|
4440
|
/**
|
4441
|
* @nocollapse
|
4442
|
*/
|
4443
|
FormControlDirective.ctorParameters = () => [
|
4444
|
{ type: Array, decorators: [{ type: Optional }, { type: Self }, { type: Inject, args: [NG_VALIDATORS,] },] },
|
4445
|
{ type: Array, decorators: [{ type: Optional }, { type: Self }, { type: Inject, args: [NG_ASYNC_VALIDATORS,] },] },
|
4446
|
{ type: Array, decorators: [{ type: Optional }, { type: Self }, { type: Inject, args: [NG_VALUE_ACCESSOR,] },] },
|
4447
|
];
|
4448
|
FormControlDirective.propDecorators = {
|
4449
|
'form': [{ type: Input, args: ['formControl',] },],
|
4450
|
'model': [{ type: Input, args: ['ngModel',] },],
|
4451
|
'update': [{ type: Output, args: ['ngModelChange',] },],
|
4452
|
'isDisabled': [{ type: Input, args: ['disabled',] },],
|
4453
|
};
|
4454
|
|
4455
|
/**
|
4456
|
* @license
|
4457
|
* Copyright Google Inc. All Rights Reserved.
|
4458
|
*
|
4459
|
* Use of this source code is governed by an MIT-style license that can be
|
4460
|
* found in the LICENSE file at https://angular.io/license
|
4461
|
*/
|
4462
|
const formDirectiveProvider$1 = {
|
4463
|
provide: ControlContainer,
|
4464
|
useExisting: forwardRef(() => FormGroupDirective)
|
4465
|
};
|
4466
|
/**
|
4467
|
* \@whatItDoes Binds an existing {\@link FormGroup} to a DOM element.
|
4468
|
*
|
4469
|
* \@howToUse
|
4470
|
*
|
4471
|
* This directive accepts an existing {\@link FormGroup} instance. It will then use this
|
4472
|
* {\@link FormGroup} instance to match any child {\@link FormControl}, {\@link FormGroup},
|
4473
|
* and {\@link FormArray} instances to child {\@link FormControlName}, {\@link FormGroupName},
|
4474
|
* and {\@link FormArrayName} directives.
|
4475
|
*
|
4476
|
* **Set value**: You can set the form's initial value when instantiating the
|
4477
|
* {\@link FormGroup}, or you can set it programmatically later using the {\@link FormGroup}'s
|
4478
|
* {\@link AbstractControl#setValue setValue} or {\@link AbstractControl#patchValue patchValue}
|
4479
|
* methods.
|
4480
|
*
|
4481
|
* **Listen to value**: If you want to listen to changes in the value of the form, you can subscribe
|
4482
|
* to the {\@link FormGroup}'s {\@link AbstractControl#valueChanges valueChanges} event. You can also
|
4483
|
* listen to its {\@link AbstractControl#statusChanges statusChanges} event to be notified when the
|
4484
|
* validation status is re-calculated.
|
4485
|
*
|
4486
|
* Furthermore, you can listen to the directive's `ngSubmit` event to be notified when the user has
|
4487
|
* triggered a form submission. The `ngSubmit` event will be emitted with the original form
|
4488
|
* submission event.
|
4489
|
*
|
4490
|
* ### Example
|
4491
|
*
|
4492
|
* In this example, we create form controls for first name and last name.
|
4493
|
*
|
4494
|
* {\@example forms/ts/simpleFormGroup/simple_form_group_example.ts region='Component'}
|
4495
|
*
|
4496
|
* **npm package**: `\@angular/forms`
|
4497
|
*
|
4498
|
* **NgModule**: {\@link ReactiveFormsModule}
|
4499
|
*
|
4500
|
* \@stable
|
4501
|
*/
|
4502
|
class FormGroupDirective extends ControlContainer {
|
4503
|
/**
|
4504
|
* @param {?} _validators
|
4505
|
* @param {?} _asyncValidators
|
4506
|
*/
|
4507
|
constructor(_validators, _asyncValidators) {
|
4508
|
super();
|
4509
|
this._validators = _validators;
|
4510
|
this._asyncValidators = _asyncValidators;
|
4511
|
this._submitted = false;
|
4512
|
this.directives = [];
|
4513
|
this.form = ((null));
|
4514
|
this.ngSubmit = new EventEmitter();
|
4515
|
}
|
4516
|
/**
|
4517
|
* @param {?} changes
|
4518
|
* @return {?}
|
4519
|
*/
|
4520
|
ngOnChanges(changes) {
|
4521
|
this._checkFormPresent();
|
4522
|
if (changes.hasOwnProperty('form')) {
|
4523
|
this._updateValidators();
|
4524
|
this._updateDomValue();
|
4525
|
this._updateRegistrations();
|
4526
|
}
|
4527
|
}
|
4528
|
/**
|
4529
|
* @return {?}
|
4530
|
*/
|
4531
|
get submitted() { return this._submitted; }
|
4532
|
/**
|
4533
|
* @return {?}
|
4534
|
*/
|
4535
|
get formDirective() { return this; }
|
4536
|
/**
|
4537
|
* @return {?}
|
4538
|
*/
|
4539
|
get control() { return this.form; }
|
4540
|
/**
|
4541
|
* @return {?}
|
4542
|
*/
|
4543
|
get path() { return []; }
|
4544
|
/**
|
4545
|
* @param {?} dir
|
4546
|
* @return {?}
|
4547
|
*/
|
4548
|
addControl(dir) {
|
4549
|
const /** @type {?} */ ctrl = this.form.get(dir.path);
|
4550
|
setUpControl(ctrl, dir);
|
4551
|
ctrl.updateValueAndValidity({ emitEvent: false });
|
4552
|
this.directives.push(dir);
|
4553
|
return ctrl;
|
4554
|
}
|
4555
|
/**
|
4556
|
* @param {?} dir
|
4557
|
* @return {?}
|
4558
|
*/
|
4559
|
getControl(dir) { return (this.form.get(dir.path)); }
|
4560
|
/**
|
4561
|
* @param {?} dir
|
4562
|
* @return {?}
|
4563
|
*/
|
4564
|
removeControl(dir) { remove(this.directives, dir); }
|
4565
|
/**
|
4566
|
* @param {?} dir
|
4567
|
* @return {?}
|
4568
|
*/
|
4569
|
addFormGroup(dir) {
|
4570
|
const /** @type {?} */ ctrl = this.form.get(dir.path);
|
4571
|
setUpFormContainer(ctrl, dir);
|
4572
|
ctrl.updateValueAndValidity({ emitEvent: false });
|
4573
|
}
|
4574
|
/**
|
4575
|
* @param {?} dir
|
4576
|
* @return {?}
|
4577
|
*/
|
4578
|
removeFormGroup(dir) { }
|
4579
|
/**
|
4580
|
* @param {?} dir
|
4581
|
* @return {?}
|
4582
|
*/
|
4583
|
getFormGroup(dir) { return (this.form.get(dir.path)); }
|
4584
|
/**
|
4585
|
* @param {?} dir
|
4586
|
* @return {?}
|
4587
|
*/
|
4588
|
addFormArray(dir) {
|
4589
|
const /** @type {?} */ ctrl = this.form.get(dir.path);
|
4590
|
setUpFormContainer(ctrl, dir);
|
4591
|
ctrl.updateValueAndValidity({ emitEvent: false });
|
4592
|
}
|
4593
|
/**
|
4594
|
* @param {?} dir
|
4595
|
* @return {?}
|
4596
|
*/
|
4597
|
removeFormArray(dir) { }
|
4598
|
/**
|
4599
|
* @param {?} dir
|
4600
|
* @return {?}
|
4601
|
*/
|
4602
|
getFormArray(dir) { return (this.form.get(dir.path)); }
|
4603
|
/**
|
4604
|
* @param {?} dir
|
4605
|
* @param {?} value
|
4606
|
* @return {?}
|
4607
|
*/
|
4608
|
updateModel(dir, value) {
|
4609
|
const /** @type {?} */ ctrl = (this.form.get(dir.path));
|
4610
|
ctrl.setValue(value);
|
4611
|
}
|
4612
|
/**
|
4613
|
* @param {?} $event
|
4614
|
* @return {?}
|
4615
|
*/
|
4616
|
onSubmit($event) {
|
4617
|
this._submitted = true;
|
4618
|
this.ngSubmit.emit($event);
|
4619
|
return false;
|
4620
|
}
|
4621
|
/**
|
4622
|
* @return {?}
|
4623
|
*/
|
4624
|
onReset() { this.resetForm(); }
|
4625
|
/**
|
4626
|
* @param {?=} value
|
4627
|
* @return {?}
|
4628
|
*/
|
4629
|
resetForm(value = undefined) {
|
4630
|
this.form.reset(value);
|
4631
|
this._submitted = false;
|
4632
|
}
|
4633
|
/**
|
4634
|
* \@internal
|
4635
|
* @return {?}
|
4636
|
*/
|
4637
|
_updateDomValue() {
|
4638
|
this.directives.forEach(dir => {
|
4639
|
const /** @type {?} */ newCtrl = this.form.get(dir.path);
|
4640
|
if (dir._control !== newCtrl) {
|
4641
|
cleanUpControl(dir._control, dir);
|
4642
|
if (newCtrl)
|
4643
|
setUpControl(newCtrl, dir);
|
4644
|
dir._control = newCtrl;
|
4645
|
}
|
4646
|
});
|
4647
|
this.form._updateTreeValidity({ emitEvent: false });
|
4648
|
}
|
4649
|
/**
|
4650
|
* @return {?}
|
4651
|
*/
|
4652
|
_updateRegistrations() {
|
4653
|
this.form._registerOnCollectionChange(() => this._updateDomValue());
|
4654
|
if (this._oldForm)
|
4655
|
this._oldForm._registerOnCollectionChange(() => { });
|
4656
|
this._oldForm = this.form;
|
4657
|
}
|
4658
|
/**
|
4659
|
* @return {?}
|
4660
|
*/
|
4661
|
_updateValidators() {
|
4662
|
const /** @type {?} */ sync = composeValidators(this._validators);
|
4663
|
this.form.validator = Validators.compose([/** @type {?} */ ((this.form.validator)), /** @type {?} */ ((sync))]);
|
4664
|
const /** @type {?} */ async = composeAsyncValidators(this._asyncValidators);
|
4665
|
this.form.asyncValidator = Validators.composeAsync([/** @type {?} */ ((this.form.asyncValidator)), /** @type {?} */ ((async))]);
|
4666
|
}
|
4667
|
/**
|
4668
|
* @return {?}
|
4669
|
*/
|
4670
|
_checkFormPresent() {
|
4671
|
if (!this.form) {
|
4672
|
ReactiveErrors.missingFormException();
|
4673
|
}
|
4674
|
}
|
4675
|
}
|
4676
|
FormGroupDirective.decorators = [
|
4677
|
{ type: Directive, args: [{
|
4678
|
selector: '[formGroup]',
|
4679
|
providers: [formDirectiveProvider$1],
|
4680
|
host: { '(submit)': 'onSubmit($event)', '(reset)': 'onReset()' },
|
4681
|
exportAs: 'ngForm'
|
4682
|
},] },
|
4683
|
];
|
4684
|
/**
|
4685
|
* @nocollapse
|
4686
|
*/
|
4687
|
FormGroupDirective.ctorParameters = () => [
|
4688
|
{ type: Array, decorators: [{ type: Optional }, { type: Self }, { type: Inject, args: [NG_VALIDATORS,] },] },
|
4689
|
{ type: Array, decorators: [{ type: Optional }, { type: Self }, { type: Inject, args: [NG_ASYNC_VALIDATORS,] },] },
|
4690
|
];
|
4691
|
FormGroupDirective.propDecorators = {
|
4692
|
'form': [{ type: Input, args: ['formGroup',] },],
|
4693
|
'ngSubmit': [{ type: Output },],
|
4694
|
};
|
4695
|
/**
|
4696
|
* @template T
|
4697
|
* @param {?} list
|
4698
|
* @param {?} el
|
4699
|
* @return {?}
|
4700
|
*/
|
4701
|
function remove(list, el) {
|
4702
|
const /** @type {?} */ index = list.indexOf(el);
|
4703
|
if (index > -1) {
|
4704
|
list.splice(index, 1);
|
4705
|
}
|
4706
|
}
|
4707
|
|
4708
|
/**
|
4709
|
* @license
|
4710
|
* Copyright Google Inc. All Rights Reserved.
|
4711
|
*
|
4712
|
* Use of this source code is governed by an MIT-style license that can be
|
4713
|
* found in the LICENSE file at https://angular.io/license
|
4714
|
*/
|
4715
|
const formGroupNameProvider = {
|
4716
|
provide: ControlContainer,
|
4717
|
useExisting: forwardRef(() => FormGroupName)
|
4718
|
};
|
4719
|
/**
|
4720
|
* \@whatItDoes Syncs a nested {\@link FormGroup} to a DOM element.
|
4721
|
*
|
4722
|
* \@howToUse
|
4723
|
*
|
4724
|
* This directive can only be used with a parent {\@link FormGroupDirective} (selector:
|
4725
|
* `[formGroup]`).
|
4726
|
*
|
4727
|
* It accepts the string name of the nested {\@link FormGroup} you want to link, and
|
4728
|
* will look for a {\@link FormGroup} registered with that name in the parent
|
4729
|
* {\@link FormGroup} instance you passed into {\@link FormGroupDirective}.
|
4730
|
*
|
4731
|
* Nested form groups can come in handy when you want to validate a sub-group of a
|
4732
|
* form separately from the rest or when you'd like to group the values of certain
|
4733
|
* controls into their own nested object.
|
4734
|
*
|
4735
|
* **Access the group**: You can access the associated {\@link FormGroup} using the
|
4736
|
* {\@link AbstractControl#get} method. Ex: `this.form.get('name')`.
|
4737
|
*
|
4738
|
* You can also access individual controls within the group using dot syntax.
|
4739
|
* Ex: `this.form.get('name.first')`
|
4740
|
*
|
4741
|
* **Get the value**: the `value` property is always synced and available on the
|
4742
|
* {\@link FormGroup}. See a full list of available properties in {\@link AbstractControl}.
|
4743
|
*
|
4744
|
* **Set the value**: You can set an initial value for each child control when instantiating
|
4745
|
* the {\@link FormGroup}, or you can set it programmatically later using
|
4746
|
* {\@link AbstractControl#setValue setValue} or {\@link AbstractControl#patchValue patchValue}.
|
4747
|
*
|
4748
|
* **Listen to value**: If you want to listen to changes in the value of the group, you can
|
4749
|
* subscribe to the {\@link AbstractControl#valueChanges valueChanges} event. You can also listen to
|
4750
|
* {\@link AbstractControl#statusChanges statusChanges} to be notified when the validation status is
|
4751
|
* re-calculated.
|
4752
|
*
|
4753
|
* ### Example
|
4754
|
*
|
4755
|
* {\@example forms/ts/nestedFormGroup/nested_form_group_example.ts region='Component'}
|
4756
|
*
|
4757
|
* * **npm package**: `\@angular/forms`
|
4758
|
*
|
4759
|
* * **NgModule**: `ReactiveFormsModule`
|
4760
|
*
|
4761
|
* \@stable
|
4762
|
*/
|
4763
|
class FormGroupName extends AbstractFormGroupDirective {
|
4764
|
/**
|
4765
|
* @param {?} parent
|
4766
|
* @param {?} validators
|
4767
|
* @param {?} asyncValidators
|
4768
|
*/
|
4769
|
constructor(parent, validators, asyncValidators) {
|
4770
|
super();
|
4771
|
this._parent = parent;
|
4772
|
this._validators = validators;
|
4773
|
this._asyncValidators = asyncValidators;
|
4774
|
}
|
4775
|
/**
|
4776
|
* \@internal
|
4777
|
* @return {?}
|
4778
|
*/
|
4779
|
_checkParentType() {
|
4780
|
if (_hasInvalidParent(this._parent)) {
|
4781
|
ReactiveErrors.groupParentException();
|
4782
|
}
|
4783
|
}
|
4784
|
}
|
4785
|
FormGroupName.decorators = [
|
4786
|
{ type: Directive, args: [{ selector: '[formGroupName]', providers: [formGroupNameProvider] },] },
|
4787
|
];
|
4788
|
/**
|
4789
|
* @nocollapse
|
4790
|
*/
|
4791
|
FormGroupName.ctorParameters = () => [
|
4792
|
{ type: ControlContainer, decorators: [{ type: Optional }, { type: Host }, { type: SkipSelf },] },
|
4793
|
{ type: Array, decorators: [{ type: Optional }, { type: Self }, { type: Inject, args: [NG_VALIDATORS,] },] },
|
4794
|
{ type: Array, decorators: [{ type: Optional }, { type: Self }, { type: Inject, args: [NG_ASYNC_VALIDATORS,] },] },
|
4795
|
];
|
4796
|
FormGroupName.propDecorators = {
|
4797
|
'name': [{ type: Input, args: ['formGroupName',] },],
|
4798
|
};
|
4799
|
const formArrayNameProvider = {
|
4800
|
provide: ControlContainer,
|
4801
|
useExisting: forwardRef(() => FormArrayName)
|
4802
|
};
|
4803
|
/**
|
4804
|
* \@whatItDoes Syncs a nested {\@link FormArray} to a DOM element.
|
4805
|
*
|
4806
|
* \@howToUse
|
4807
|
*
|
4808
|
* This directive is designed to be used with a parent {\@link FormGroupDirective} (selector:
|
4809
|
* `[formGroup]`).
|
4810
|
*
|
4811
|
* It accepts the string name of the nested {\@link FormArray} you want to link, and
|
4812
|
* will look for a {\@link FormArray} registered with that name in the parent
|
4813
|
* {\@link FormGroup} instance you passed into {\@link FormGroupDirective}.
|
4814
|
*
|
4815
|
* Nested form arrays can come in handy when you have a group of form controls but
|
4816
|
* you're not sure how many there will be. Form arrays allow you to create new
|
4817
|
* form controls dynamically.
|
4818
|
*
|
4819
|
* **Access the array**: You can access the associated {\@link FormArray} using the
|
4820
|
* {\@link AbstractControl#get} method on the parent {\@link FormGroup}.
|
4821
|
* Ex: `this.form.get('cities')`.
|
4822
|
*
|
4823
|
* **Get the value**: the `value` property is always synced and available on the
|
4824
|
* {\@link FormArray}. See a full list of available properties in {\@link AbstractControl}.
|
4825
|
*
|
4826
|
* **Set the value**: You can set an initial value for each child control when instantiating
|
4827
|
* the {\@link FormArray}, or you can set the value programmatically later using the
|
4828
|
* {\@link FormArray}'s {\@link AbstractControl#setValue} or {\@link AbstractControl#patchValue}
|
4829
|
* methods.
|
4830
|
*
|
4831
|
* **Listen to value**: If you want to listen to changes in the value of the array, you can
|
4832
|
* subscribe to the {\@link FormArray}'s {\@link AbstractControl#valueChanges} event. You can also
|
4833
|
* listen to its {\@link AbstractControl#statusChanges} event to be notified when the validation
|
4834
|
* status is re-calculated.
|
4835
|
*
|
4836
|
* **Add new controls**: You can add new controls to the {\@link FormArray} dynamically by
|
4837
|
* calling its {\@link FormArray#push} method.
|
4838
|
* Ex: `this.form.get('cities').push(new FormControl());`
|
4839
|
*
|
4840
|
* ### Example
|
4841
|
*
|
4842
|
* {\@example forms/ts/nestedFormArray/nested_form_array_example.ts region='Component'}
|
4843
|
*
|
4844
|
* * **npm package**: `\@angular/forms`
|
4845
|
*
|
4846
|
* * **NgModule**: `ReactiveFormsModule`
|
4847
|
*
|
4848
|
* \@stable
|
4849
|
*/
|
4850
|
class FormArrayName extends ControlContainer {
|
4851
|
/**
|
4852
|
* @param {?} parent
|
4853
|
* @param {?} validators
|
4854
|
* @param {?} asyncValidators
|
4855
|
*/
|
4856
|
constructor(parent, validators, asyncValidators) {
|
4857
|
super();
|
4858
|
this._parent = parent;
|
4859
|
this._validators = validators;
|
4860
|
this._asyncValidators = asyncValidators;
|
4861
|
}
|
4862
|
/**
|
4863
|
* @return {?}
|
4864
|
*/
|
4865
|
ngOnInit() {
|
4866
|
this._checkParentType(); /** @type {?} */
|
4867
|
((this.formDirective)).addFormArray(this);
|
4868
|
}
|
4869
|
/**
|
4870
|
* @return {?}
|
4871
|
*/
|
4872
|
ngOnDestroy() {
|
4873
|
if (this.formDirective) {
|
4874
|
this.formDirective.removeFormArray(this);
|
4875
|
}
|
4876
|
}
|
4877
|
/**
|
4878
|
* @return {?}
|
4879
|
*/
|
4880
|
get control() { return ((this.formDirective)).getFormArray(this); }
|
4881
|
/**
|
4882
|
* @return {?}
|
4883
|
*/
|
4884
|
get formDirective() {
|
4885
|
return this._parent ? (this._parent.formDirective) : null;
|
4886
|
}
|
4887
|
/**
|
4888
|
* @return {?}
|
4889
|
*/
|
4890
|
get path() { return controlPath(this.name, this._parent); }
|
4891
|
/**
|
4892
|
* @return {?}
|
4893
|
*/
|
4894
|
get validator() { return composeValidators(this._validators); }
|
4895
|
/**
|
4896
|
* @return {?}
|
4897
|
*/
|
4898
|
get asyncValidator() {
|
4899
|
return composeAsyncValidators(this._asyncValidators);
|
4900
|
}
|
4901
|
/**
|
4902
|
* @return {?}
|
4903
|
*/
|
4904
|
_checkParentType() {
|
4905
|
if (_hasInvalidParent(this._parent)) {
|
4906
|
ReactiveErrors.arrayParentException();
|
4907
|
}
|
4908
|
}
|
4909
|
}
|
4910
|
FormArrayName.decorators = [
|
4911
|
{ type: Directive, args: [{ selector: '[formArrayName]', providers: [formArrayNameProvider] },] },
|
4912
|
];
|
4913
|
/**
|
4914
|
* @nocollapse
|
4915
|
*/
|
4916
|
FormArrayName.ctorParameters = () => [
|
4917
|
{ type: ControlContainer, decorators: [{ type: Optional }, { type: Host }, { type: SkipSelf },] },
|
4918
|
{ type: Array, decorators: [{ type: Optional }, { type: Self }, { type: Inject, args: [NG_VALIDATORS,] },] },
|
4919
|
{ type: Array, decorators: [{ type: Optional }, { type: Self }, { type: Inject, args: [NG_ASYNC_VALIDATORS,] },] },
|
4920
|
];
|
4921
|
FormArrayName.propDecorators = {
|
4922
|
'name': [{ type: Input, args: ['formArrayName',] },],
|
4923
|
};
|
4924
|
/**
|
4925
|
* @param {?} parent
|
4926
|
* @return {?}
|
4927
|
*/
|
4928
|
function _hasInvalidParent(parent) {
|
4929
|
return !(parent instanceof FormGroupName) && !(parent instanceof FormGroupDirective) &&
|
4930
|
!(parent instanceof FormArrayName);
|
4931
|
}
|
4932
|
|
4933
|
/**
|
4934
|
* @license
|
4935
|
* Copyright Google Inc. All Rights Reserved.
|
4936
|
*
|
4937
|
* Use of this source code is governed by an MIT-style license that can be
|
4938
|
* found in the LICENSE file at https://angular.io/license
|
4939
|
*/
|
4940
|
const controlNameBinding = {
|
4941
|
provide: NgControl,
|
4942
|
useExisting: forwardRef(() => FormControlName)
|
4943
|
};
|
4944
|
/**
|
4945
|
* \@whatItDoes Syncs a {\@link FormControl} in an existing {\@link FormGroup} to a form control
|
4946
|
* element by name.
|
4947
|
*
|
4948
|
* In other words, this directive ensures that any values written to the {\@link FormControl}
|
4949
|
* instance programmatically will be written to the DOM element (model -> view). Conversely,
|
4950
|
* any values written to the DOM element through user input will be reflected in the
|
4951
|
* {\@link FormControl} instance (view -> model).
|
4952
|
*
|
4953
|
* \@howToUse
|
4954
|
*
|
4955
|
* This directive is designed to be used with a parent {\@link FormGroupDirective} (selector:
|
4956
|
* `[formGroup]`).
|
4957
|
*
|
4958
|
* It accepts the string name of the {\@link FormControl} instance you want to
|
4959
|
* link, and will look for a {\@link FormControl} registered with that name in the
|
4960
|
* closest {\@link FormGroup} or {\@link FormArray} above it.
|
4961
|
*
|
4962
|
* **Access the control**: You can access the {\@link FormControl} associated with
|
4963
|
* this directive by using the {\@link AbstractControl#get get} method.
|
4964
|
* Ex: `this.form.get('first');`
|
4965
|
*
|
4966
|
* **Get value**: the `value` property is always synced and available on the {\@link FormControl}.
|
4967
|
* See a full list of available properties in {\@link AbstractControl}.
|
4968
|
*
|
4969
|
* **Set value**: You can set an initial value for the control when instantiating the
|
4970
|
* {\@link FormControl}, or you can set it programmatically later using
|
4971
|
* {\@link AbstractControl#setValue setValue} or {\@link AbstractControl#patchValue patchValue}.
|
4972
|
*
|
4973
|
* **Listen to value**: If you want to listen to changes in the value of the control, you can
|
4974
|
* subscribe to the {\@link AbstractControl#valueChanges valueChanges} event. You can also listen to
|
4975
|
* {\@link AbstractControl#statusChanges statusChanges} to be notified when the validation status is
|
4976
|
* re-calculated.
|
4977
|
*
|
4978
|
* ### Example
|
4979
|
*
|
4980
|
* In this example, we create form controls for first name and last name.
|
4981
|
*
|
4982
|
* {\@example forms/ts/simpleFormGroup/simple_form_group_example.ts region='Component'}
|
4983
|
*
|
4984
|
* To see `formControlName` examples with different form control types, see:
|
4985
|
*
|
4986
|
* * Radio buttons: {\@link RadioControlValueAccessor}
|
4987
|
* * Selects: {\@link SelectControlValueAccessor}
|
4988
|
*
|
4989
|
* **npm package**: `\@angular/forms`
|
4990
|
*
|
4991
|
* **NgModule**: {\@link ReactiveFormsModule}
|
4992
|
*
|
4993
|
* \@stable
|
4994
|
*/
|
4995
|
class FormControlName extends NgControl {
|
4996
|
/**
|
4997
|
* @param {?} parent
|
4998
|
* @param {?} validators
|
4999
|
* @param {?} asyncValidators
|
5000
|
* @param {?} valueAccessors
|
5001
|
*/
|
5002
|
constructor(parent, validators, asyncValidators, valueAccessors) {
|
5003
|
super();
|
5004
|
this._added = false;
|
5005
|
this.update = new EventEmitter();
|
5006
|
this._parent = parent;
|
5007
|
this._rawValidators = validators || [];
|
5008
|
this._rawAsyncValidators = asyncValidators || [];
|
5009
|
this.valueAccessor = selectValueAccessor(this, valueAccessors);
|
5010
|
}
|
5011
|
/**
|
5012
|
* @param {?} isDisabled
|
5013
|
* @return {?}
|
5014
|
*/
|
5015
|
set isDisabled(isDisabled) { ReactiveErrors.disabledAttrWarning(); }
|
5016
|
/**
|
5017
|
* @param {?} changes
|
5018
|
* @return {?}
|
5019
|
*/
|
5020
|
ngOnChanges(changes) {
|
5021
|
if (!this._added)
|
5022
|
this._setUpControl();
|
5023
|
if (isPropertyUpdated(changes, this.viewModel)) {
|
5024
|
this.viewModel = this.model;
|
5025
|
this.formDirective.updateModel(this, this.model);
|
5026
|
}
|
5027
|
}
|
5028
|
/**
|
5029
|
* @return {?}
|
5030
|
*/
|
5031
|
ngOnDestroy() {
|
5032
|
if (this.formDirective) {
|
5033
|
this.formDirective.removeControl(this);
|
5034
|
}
|
5035
|
}
|
5036
|
/**
|
5037
|
* @param {?} newValue
|
5038
|
* @return {?}
|
5039
|
*/
|
5040
|
viewToModelUpdate(newValue) {
|
5041
|
this.viewModel = newValue;
|
5042
|
this.update.emit(newValue);
|
5043
|
}
|
5044
|
/**
|
5045
|
* @return {?}
|
5046
|
*/
|
5047
|
get path() { return controlPath(this.name, /** @type {?} */ ((this._parent))); }
|
5048
|
/**
|
5049
|
* @return {?}
|
5050
|
*/
|
5051
|
get formDirective() { return this._parent ? this._parent.formDirective : null; }
|
5052
|
/**
|
5053
|
* @return {?}
|
5054
|
*/
|
5055
|
get validator() { return composeValidators(this._rawValidators); }
|
5056
|
/**
|
5057
|
* @return {?}
|
5058
|
*/
|
5059
|
get asyncValidator() {
|
5060
|
return ((composeAsyncValidators(this._rawAsyncValidators)));
|
5061
|
}
|
5062
|
/**
|
5063
|
* @return {?}
|
5064
|
*/
|
5065
|
get control() { return this._control; }
|
5066
|
/**
|
5067
|
* @return {?}
|
5068
|
*/
|
5069
|
_checkParentType() {
|
5070
|
if (!(this._parent instanceof FormGroupName) &&
|
5071
|
this._parent instanceof AbstractFormGroupDirective) {
|
5072
|
ReactiveErrors.ngModelGroupException();
|
5073
|
}
|
5074
|
else if (!(this._parent instanceof FormGroupName) && !(this._parent instanceof FormGroupDirective) &&
|
5075
|
!(this._parent instanceof FormArrayName)) {
|
5076
|
ReactiveErrors.controlParentException();
|
5077
|
}
|
5078
|
}
|
5079
|
/**
|
5080
|
* @return {?}
|
5081
|
*/
|
5082
|
_setUpControl() {
|
5083
|
this._checkParentType();
|
5084
|
this._control = this.formDirective.addControl(this);
|
5085
|
if (this.control.disabled && ((this.valueAccessor)).setDisabledState) {
|
5086
|
((((this.valueAccessor)).setDisabledState))(true);
|
5087
|
}
|
5088
|
this._added = true;
|
5089
|
}
|
5090
|
}
|
5091
|
FormControlName.decorators = [
|
5092
|
{ type: Directive, args: [{ selector: '[formControlName]', providers: [controlNameBinding] },] },
|
5093
|
];
|
5094
|
/**
|
5095
|
* @nocollapse
|
5096
|
*/
|
5097
|
FormControlName.ctorParameters = () => [
|
5098
|
{ type: ControlContainer, decorators: [{ type: Optional }, { type: Host }, { type: SkipSelf },] },
|
5099
|
{ type: Array, decorators: [{ type: Optional }, { type: Self }, { type: Inject, args: [NG_VALIDATORS,] },] },
|
5100
|
{ type: Array, decorators: [{ type: Optional }, { type: Self }, { type: Inject, args: [NG_ASYNC_VALIDATORS,] },] },
|
5101
|
{ type: Array, decorators: [{ type: Optional }, { type: Self }, { type: Inject, args: [NG_VALUE_ACCESSOR,] },] },
|
5102
|
];
|
5103
|
FormControlName.propDecorators = {
|
5104
|
'name': [{ type: Input, args: ['formControlName',] },],
|
5105
|
'model': [{ type: Input, args: ['ngModel',] },],
|
5106
|
'update': [{ type: Output, args: ['ngModelChange',] },],
|
5107
|
'isDisabled': [{ type: Input, args: ['disabled',] },],
|
5108
|
};
|
5109
|
|
5110
|
/**
|
5111
|
* @license
|
5112
|
* Copyright Google Inc. All Rights Reserved.
|
5113
|
*
|
5114
|
* Use of this source code is governed by an MIT-style license that can be
|
5115
|
* found in the LICENSE file at https://angular.io/license
|
5116
|
*/
|
5117
|
const REQUIRED_VALIDATOR = {
|
5118
|
provide: NG_VALIDATORS,
|
5119
|
useExisting: forwardRef(() => RequiredValidator),
|
5120
|
multi: true
|
5121
|
};
|
5122
|
const CHECKBOX_REQUIRED_VALIDATOR = {
|
5123
|
provide: NG_VALIDATORS,
|
5124
|
useExisting: forwardRef(() => CheckboxRequiredValidator),
|
5125
|
multi: true
|
5126
|
};
|
5127
|
/**
|
5128
|
* A Directive that adds the `required` validator to any controls marked with the
|
5129
|
* `required` attribute, via the {\@link NG_VALIDATORS} binding.
|
5130
|
*
|
5131
|
* ### Example
|
5132
|
*
|
5133
|
* ```
|
5134
|
* <input name="fullName" ngModel required>
|
5135
|
* ```
|
5136
|
*
|
5137
|
* \@stable
|
5138
|
*/
|
5139
|
class RequiredValidator {
|
5140
|
/**
|
5141
|
* @return {?}
|
5142
|
*/
|
5143
|
get required() { return this._required; }
|
5144
|
/**
|
5145
|
* @param {?} value
|
5146
|
* @return {?}
|
5147
|
*/
|
5148
|
set required(value) {
|
5149
|
this._required = value != null && value !== false && `${value}` !== 'false';
|
5150
|
if (this._onChange)
|
5151
|
this._onChange();
|
5152
|
}
|
5153
|
/**
|
5154
|
* @param {?} c
|
5155
|
* @return {?}
|
5156
|
*/
|
5157
|
validate(c) {
|
5158
|
return this.required ? Validators.required(c) : null;
|
5159
|
}
|
5160
|
/**
|
5161
|
* @param {?} fn
|
5162
|
* @return {?}
|
5163
|
*/
|
5164
|
registerOnValidatorChange(fn) { this._onChange = fn; }
|
5165
|
}
|
5166
|
RequiredValidator.decorators = [
|
5167
|
{ type: Directive, args: [{
|
5168
|
selector: ':not([type=checkbox])[required][formControlName],:not([type=checkbox])[required][formControl],:not([type=checkbox])[required][ngModel]',
|
5169
|
providers: [REQUIRED_VALIDATOR],
|
5170
|
host: { '[attr.required]': 'required ? "" : null' }
|
5171
|
},] },
|
5172
|
];
|
5173
|
/**
|
5174
|
* @nocollapse
|
5175
|
*/
|
5176
|
RequiredValidator.ctorParameters = () => [];
|
5177
|
RequiredValidator.propDecorators = {
|
5178
|
'required': [{ type: Input },],
|
5179
|
};
|
5180
|
/**
|
5181
|
* A Directive that adds the `required` validator to checkbox controls marked with the
|
5182
|
* `required` attribute, via the {\@link NG_VALIDATORS} binding.
|
5183
|
*
|
5184
|
* ### Example
|
5185
|
*
|
5186
|
* ```
|
5187
|
* <input type="checkbox" name="active" ngModel required>
|
5188
|
* ```
|
5189
|
*
|
5190
|
* \@experimental
|
5191
|
*/
|
5192
|
class CheckboxRequiredValidator extends RequiredValidator {
|
5193
|
/**
|
5194
|
* @param {?} c
|
5195
|
* @return {?}
|
5196
|
*/
|
5197
|
validate(c) {
|
5198
|
return this.required ? Validators.requiredTrue(c) : null;
|
5199
|
}
|
5200
|
}
|
5201
|
CheckboxRequiredValidator.decorators = [
|
5202
|
{ type: Directive, args: [{
|
5203
|
selector: 'input[type=checkbox][required][formControlName],input[type=checkbox][required][formControl],input[type=checkbox][required][ngModel]',
|
5204
|
providers: [CHECKBOX_REQUIRED_VALIDATOR],
|
5205
|
host: { '[attr.required]': 'required ? "" : null' }
|
5206
|
},] },
|
5207
|
];
|
5208
|
/**
|
5209
|
* @nocollapse
|
5210
|
*/
|
5211
|
CheckboxRequiredValidator.ctorParameters = () => [];
|
5212
|
/**
|
5213
|
* Provider which adds {\@link EmailValidator} to {\@link NG_VALIDATORS}.
|
5214
|
*/
|
5215
|
const EMAIL_VALIDATOR = {
|
5216
|
provide: NG_VALIDATORS,
|
5217
|
useExisting: forwardRef(() => EmailValidator),
|
5218
|
multi: true
|
5219
|
};
|
5220
|
/**
|
5221
|
* A Directive that adds the `email` validator to controls marked with the
|
5222
|
* `email` attribute, via the {\@link NG_VALIDATORS} binding.
|
5223
|
*
|
5224
|
* ### Example
|
5225
|
*
|
5226
|
* ```
|
5227
|
* <input type="email" name="email" ngModel email>
|
5228
|
* <input type="email" name="email" ngModel email="true">
|
5229
|
* <input type="email" name="email" ngModel [email]="true">
|
5230
|
* ```
|
5231
|
*
|
5232
|
* \@experimental
|
5233
|
*/
|
5234
|
class EmailValidator {
|
5235
|
/**
|
5236
|
* @param {?} value
|
5237
|
* @return {?}
|
5238
|
*/
|
5239
|
set email(value) {
|
5240
|
this._enabled = value === '' || value === true || value === 'true';
|
5241
|
if (this._onChange)
|
5242
|
this._onChange();
|
5243
|
}
|
5244
|
/**
|
5245
|
* @param {?} c
|
5246
|
* @return {?}
|
5247
|
*/
|
5248
|
validate(c) {
|
5249
|
return this._enabled ? Validators.email(c) : null;
|
5250
|
}
|
5251
|
/**
|
5252
|
* @param {?} fn
|
5253
|
* @return {?}
|
5254
|
*/
|
5255
|
registerOnValidatorChange(fn) { this._onChange = fn; }
|
5256
|
}
|
5257
|
EmailValidator.decorators = [
|
5258
|
{ type: Directive, args: [{
|
5259
|
selector: '[email][formControlName],[email][formControl],[email][ngModel]',
|
5260
|
providers: [EMAIL_VALIDATOR]
|
5261
|
},] },
|
5262
|
];
|
5263
|
/**
|
5264
|
* @nocollapse
|
5265
|
*/
|
5266
|
EmailValidator.ctorParameters = () => [];
|
5267
|
EmailValidator.propDecorators = {
|
5268
|
'email': [{ type: Input },],
|
5269
|
};
|
5270
|
/**
|
5271
|
* Provider which adds {\@link MinLengthValidator} to {\@link NG_VALIDATORS}.
|
5272
|
*
|
5273
|
* ## Example:
|
5274
|
*
|
5275
|
* {\@example common/forms/ts/validators/validators.ts region='min'}
|
5276
|
*/
|
5277
|
const MIN_LENGTH_VALIDATOR = {
|
5278
|
provide: NG_VALIDATORS,
|
5279
|
useExisting: forwardRef(() => MinLengthValidator),
|
5280
|
multi: true
|
5281
|
};
|
5282
|
/**
|
5283
|
* A directive which installs the {\@link MinLengthValidator} for any `formControlName`,
|
5284
|
* `formControl`, or control with `ngModel` that also has a `minlength` attribute.
|
5285
|
*
|
5286
|
* \@stable
|
5287
|
*/
|
5288
|
class MinLengthValidator {
|
5289
|
/**
|
5290
|
* @param {?} changes
|
5291
|
* @return {?}
|
5292
|
*/
|
5293
|
ngOnChanges(changes) {
|
5294
|
if ('minlength' in changes) {
|
5295
|
this._createValidator();
|
5296
|
if (this._onChange)
|
5297
|
this._onChange();
|
5298
|
}
|
5299
|
}
|
5300
|
/**
|
5301
|
* @param {?} c
|
5302
|
* @return {?}
|
5303
|
*/
|
5304
|
validate(c) {
|
5305
|
return this.minlength == null ? null : this._validator(c);
|
5306
|
}
|
5307
|
/**
|
5308
|
* @param {?} fn
|
5309
|
* @return {?}
|
5310
|
*/
|
5311
|
registerOnValidatorChange(fn) { this._onChange = fn; }
|
5312
|
/**
|
5313
|
* @return {?}
|
5314
|
*/
|
5315
|
_createValidator() {
|
5316
|
this._validator = Validators.minLength(parseInt(this.minlength, 10));
|
5317
|
}
|
5318
|
}
|
5319
|
MinLengthValidator.decorators = [
|
5320
|
{ type: Directive, args: [{
|
5321
|
selector: '[minlength][formControlName],[minlength][formControl],[minlength][ngModel]',
|
5322
|
providers: [MIN_LENGTH_VALIDATOR],
|
5323
|
host: { '[attr.minlength]': 'minlength ? minlength : null' }
|
5324
|
},] },
|
5325
|
];
|
5326
|
/**
|
5327
|
* @nocollapse
|
5328
|
*/
|
5329
|
MinLengthValidator.ctorParameters = () => [];
|
5330
|
MinLengthValidator.propDecorators = {
|
5331
|
'minlength': [{ type: Input },],
|
5332
|
};
|
5333
|
/**
|
5334
|
* Provider which adds {\@link MaxLengthValidator} to {\@link NG_VALIDATORS}.
|
5335
|
*
|
5336
|
* ## Example:
|
5337
|
*
|
5338
|
* {\@example common/forms/ts/validators/validators.ts region='max'}
|
5339
|
*/
|
5340
|
const MAX_LENGTH_VALIDATOR = {
|
5341
|
provide: NG_VALIDATORS,
|
5342
|
useExisting: forwardRef(() => MaxLengthValidator),
|
5343
|
multi: true
|
5344
|
};
|
5345
|
/**
|
5346
|
* A directive which installs the {\@link MaxLengthValidator} for any `formControlName,
|
5347
|
* `formControl`,
|
5348
|
* or control with `ngModel` that also has a `maxlength` attribute.
|
5349
|
*
|
5350
|
* \@stable
|
5351
|
*/
|
5352
|
class MaxLengthValidator {
|
5353
|
/**
|
5354
|
* @param {?} changes
|
5355
|
* @return {?}
|
5356
|
*/
|
5357
|
ngOnChanges(changes) {
|
5358
|
if ('maxlength' in changes) {
|
5359
|
this._createValidator();
|
5360
|
if (this._onChange)
|
5361
|
this._onChange();
|
5362
|
}
|
5363
|
}
|
5364
|
/**
|
5365
|
* @param {?} c
|
5366
|
* @return {?}
|
5367
|
*/
|
5368
|
validate(c) {
|
5369
|
return this.maxlength != null ? this._validator(c) : null;
|
5370
|
}
|
5371
|
/**
|
5372
|
* @param {?} fn
|
5373
|
* @return {?}
|
5374
|
*/
|
5375
|
registerOnValidatorChange(fn) { this._onChange = fn; }
|
5376
|
/**
|
5377
|
* @return {?}
|
5378
|
*/
|
5379
|
_createValidator() {
|
5380
|
this._validator = Validators.maxLength(parseInt(this.maxlength, 10));
|
5381
|
}
|
5382
|
}
|
5383
|
MaxLengthValidator.decorators = [
|
5384
|
{ type: Directive, args: [{
|
5385
|
selector: '[maxlength][formControlName],[maxlength][formControl],[maxlength][ngModel]',
|
5386
|
providers: [MAX_LENGTH_VALIDATOR],
|
5387
|
host: { '[attr.maxlength]': 'maxlength ? maxlength : null' }
|
5388
|
},] },
|
5389
|
];
|
5390
|
/**
|
5391
|
* @nocollapse
|
5392
|
*/
|
5393
|
MaxLengthValidator.ctorParameters = () => [];
|
5394
|
MaxLengthValidator.propDecorators = {
|
5395
|
'maxlength': [{ type: Input },],
|
5396
|
};
|
5397
|
const PATTERN_VALIDATOR = {
|
5398
|
provide: NG_VALIDATORS,
|
5399
|
useExisting: forwardRef(() => PatternValidator),
|
5400
|
multi: true
|
5401
|
};
|
5402
|
/**
|
5403
|
* A Directive that adds the `pattern` validator to any controls marked with the
|
5404
|
* `pattern` attribute, via the {\@link NG_VALIDATORS} binding. Uses attribute value
|
5405
|
* as the regex to validate Control value against. Follows pattern attribute
|
5406
|
* semantics; i.e. regex must match entire Control value.
|
5407
|
*
|
5408
|
* ### Example
|
5409
|
*
|
5410
|
* ```
|
5411
|
* <input [name]="fullName" pattern="[a-zA-Z ]*" ngModel>
|
5412
|
* ```
|
5413
|
* \@stable
|
5414
|
*/
|
5415
|
class PatternValidator {
|
5416
|
/**
|
5417
|
* @param {?} changes
|
5418
|
* @return {?}
|
5419
|
*/
|
5420
|
ngOnChanges(changes) {
|
5421
|
if ('pattern' in changes) {
|
5422
|
this._createValidator();
|
5423
|
if (this._onChange)
|
5424
|
this._onChange();
|
5425
|
}
|
5426
|
}
|
5427
|
/**
|
5428
|
* @param {?} c
|
5429
|
* @return {?}
|
5430
|
*/
|
5431
|
validate(c) { return this._validator(c); }
|
5432
|
/**
|
5433
|
* @param {?} fn
|
5434
|
* @return {?}
|
5435
|
*/
|
5436
|
registerOnValidatorChange(fn) { this._onChange = fn; }
|
5437
|
/**
|
5438
|
* @return {?}
|
5439
|
*/
|
5440
|
_createValidator() { this._validator = Validators.pattern(this.pattern); }
|
5441
|
}
|
5442
|
PatternValidator.decorators = [
|
5443
|
{ type: Directive, args: [{
|
5444
|
selector: '[pattern][formControlName],[pattern][formControl],[pattern][ngModel]',
|
5445
|
providers: [PATTERN_VALIDATOR],
|
5446
|
host: { '[attr.pattern]': 'pattern ? pattern : null' }
|
5447
|
},] },
|
5448
|
];
|
5449
|
/**
|
5450
|
* @nocollapse
|
5451
|
*/
|
5452
|
PatternValidator.ctorParameters = () => [];
|
5453
|
PatternValidator.propDecorators = {
|
5454
|
'pattern': [{ type: Input },],
|
5455
|
};
|
5456
|
|
5457
|
/**
|
5458
|
* @license
|
5459
|
* Copyright Google Inc. All Rights Reserved.
|
5460
|
*
|
5461
|
* Use of this source code is governed by an MIT-style license that can be
|
5462
|
* found in the LICENSE file at https://angular.io/license
|
5463
|
*/
|
5464
|
/**
|
5465
|
* \@whatItDoes Creates an {\@link AbstractControl} from a user-specified configuration.
|
5466
|
*
|
5467
|
* It is essentially syntactic sugar that shortens the `new FormGroup()`,
|
5468
|
* `new FormControl()`, and `new FormArray()` boilerplate that can build up in larger
|
5469
|
* forms.
|
5470
|
*
|
5471
|
* \@howToUse
|
5472
|
*
|
5473
|
* To use, inject `FormBuilder` into your component class. You can then call its methods
|
5474
|
* directly.
|
5475
|
*
|
5476
|
* {\@example forms/ts/formBuilder/form_builder_example.ts region='Component'}
|
5477
|
*
|
5478
|
* * **npm package**: `\@angular/forms`
|
5479
|
*
|
5480
|
* * **NgModule**: {\@link ReactiveFormsModule}
|
5481
|
*
|
5482
|
* \@stable
|
5483
|
*/
|
5484
|
class FormBuilder {
|
5485
|
/**
|
5486
|
* Construct a new {\@link FormGroup} with the given map of configuration.
|
5487
|
* Valid keys for the `extra` parameter map are `validator` and `asyncValidator`.
|
5488
|
*
|
5489
|
* See the {\@link FormGroup} constructor for more details.
|
5490
|
* @param {?} controlsConfig
|
5491
|
* @param {?=} extra
|
5492
|
* @return {?}
|
5493
|
*/
|
5494
|
group(controlsConfig, extra = null) {
|
5495
|
const /** @type {?} */ controls = this._reduceControls(controlsConfig);
|
5496
|
const /** @type {?} */ validator = extra != null ? extra['validator'] : null;
|
5497
|
const /** @type {?} */ asyncValidator = extra != null ? extra['asyncValidator'] : null;
|
5498
|
return new FormGroup(controls, validator, asyncValidator);
|
5499
|
}
|
5500
|
/**
|
5501
|
* Construct a new {\@link FormControl} with the given `formState`,`validator`, and
|
5502
|
* `asyncValidator`.
|
5503
|
*
|
5504
|
* `formState` can either be a standalone value for the form control or an object
|
5505
|
* that contains both a value and a disabled status.
|
5506
|
*
|
5507
|
* @param {?} formState
|
5508
|
* @param {?=} validator
|
5509
|
* @param {?=} asyncValidator
|
5510
|
* @return {?}
|
5511
|
*/
|
5512
|
control(formState, validator, asyncValidator) {
|
5513
|
return new FormControl(formState, validator, asyncValidator);
|
5514
|
}
|
5515
|
/**
|
5516
|
* Construct a {\@link FormArray} from the given `controlsConfig` array of
|
5517
|
* configuration, with the given optional `validator` and `asyncValidator`.
|
5518
|
* @param {?} controlsConfig
|
5519
|
* @param {?=} validator
|
5520
|
* @param {?=} asyncValidator
|
5521
|
* @return {?}
|
5522
|
*/
|
5523
|
array(controlsConfig, validator, asyncValidator) {
|
5524
|
const /** @type {?} */ controls = controlsConfig.map(c => this._createControl(c));
|
5525
|
return new FormArray(controls, validator, asyncValidator);
|
5526
|
}
|
5527
|
/**
|
5528
|
* \@internal
|
5529
|
* @param {?} controlsConfig
|
5530
|
* @return {?}
|
5531
|
*/
|
5532
|
_reduceControls(controlsConfig) {
|
5533
|
const /** @type {?} */ controls = {};
|
5534
|
Object.keys(controlsConfig).forEach(controlName => {
|
5535
|
controls[controlName] = this._createControl(controlsConfig[controlName]);
|
5536
|
});
|
5537
|
return controls;
|
5538
|
}
|
5539
|
/**
|
5540
|
* \@internal
|
5541
|
* @param {?} controlConfig
|
5542
|
* @return {?}
|
5543
|
*/
|
5544
|
_createControl(controlConfig) {
|
5545
|
if (controlConfig instanceof FormControl || controlConfig instanceof FormGroup ||
|
5546
|
controlConfig instanceof FormArray) {
|
5547
|
return controlConfig;
|
5548
|
}
|
5549
|
else if (Array.isArray(controlConfig)) {
|
5550
|
const /** @type {?} */ value = controlConfig[0];
|
5551
|
const /** @type {?} */ validator = controlConfig.length > 1 ? controlConfig[1] : null;
|
5552
|
const /** @type {?} */ asyncValidator = controlConfig.length > 2 ? controlConfig[2] : null;
|
5553
|
return this.control(value, validator, asyncValidator);
|
5554
|
}
|
5555
|
else {
|
5556
|
return this.control(controlConfig);
|
5557
|
}
|
5558
|
}
|
5559
|
}
|
5560
|
FormBuilder.decorators = [
|
5561
|
{ type: Injectable },
|
5562
|
];
|
5563
|
/**
|
5564
|
* @nocollapse
|
5565
|
*/
|
5566
|
FormBuilder.ctorParameters = () => [];
|
5567
|
|
5568
|
/**
|
5569
|
* @license
|
5570
|
* Copyright Google Inc. All Rights Reserved.
|
5571
|
*
|
5572
|
* Use of this source code is governed by an MIT-style license that can be
|
5573
|
* found in the LICENSE file at https://angular.io/license
|
5574
|
*/
|
5575
|
/**
|
5576
|
* @module
|
5577
|
* @description
|
5578
|
* Entry point for all public APIs of the common package.
|
5579
|
*/
|
5580
|
/**
|
5581
|
* \@stable
|
5582
|
*/
|
5583
|
const VERSION = new Version('4.4.6');
|
5584
|
|
5585
|
/**
|
5586
|
* @license
|
5587
|
* Copyright Google Inc. All Rights Reserved.
|
5588
|
*
|
5589
|
* Use of this source code is governed by an MIT-style license that can be
|
5590
|
* found in the LICENSE file at https://angular.io/license
|
5591
|
*/
|
5592
|
/**
|
5593
|
* \@whatItDoes Adds `novalidate` attribute to all forms by default.
|
5594
|
*
|
5595
|
* `novalidate` is used to disable browser's native form validation.
|
5596
|
*
|
5597
|
* If you want to use native validation with Angular forms, just add `ngNativeValidate` attribute:
|
5598
|
*
|
5599
|
* ```
|
5600
|
* <form ngNativeValidate></form>
|
5601
|
* ```
|
5602
|
*
|
5603
|
* \@experimental
|
5604
|
*/
|
5605
|
class NgNoValidate {
|
5606
|
}
|
5607
|
NgNoValidate.decorators = [
|
5608
|
{ type: Directive, args: [{
|
5609
|
selector: 'form:not([ngNoForm]):not([ngNativeValidate])',
|
5610
|
host: { 'novalidate': '' },
|
5611
|
},] },
|
5612
|
];
|
5613
|
/**
|
5614
|
* @nocollapse
|
5615
|
*/
|
5616
|
NgNoValidate.ctorParameters = () => [];
|
5617
|
|
5618
|
/**
|
5619
|
* @license
|
5620
|
* Copyright Google Inc. All Rights Reserved.
|
5621
|
*
|
5622
|
* Use of this source code is governed by an MIT-style license that can be
|
5623
|
* found in the LICENSE file at https://angular.io/license
|
5624
|
*/
|
5625
|
const SHARED_FORM_DIRECTIVES = [
|
5626
|
NgNoValidate,
|
5627
|
NgSelectOption,
|
5628
|
NgSelectMultipleOption,
|
5629
|
DefaultValueAccessor,
|
5630
|
NumberValueAccessor,
|
5631
|
RangeValueAccessor,
|
5632
|
CheckboxControlValueAccessor,
|
5633
|
SelectControlValueAccessor,
|
5634
|
SelectMultipleControlValueAccessor,
|
5635
|
RadioControlValueAccessor,
|
5636
|
NgControlStatus,
|
5637
|
NgControlStatusGroup,
|
5638
|
RequiredValidator,
|
5639
|
MinLengthValidator,
|
5640
|
MaxLengthValidator,
|
5641
|
PatternValidator,
|
5642
|
CheckboxRequiredValidator,
|
5643
|
EmailValidator,
|
5644
|
];
|
5645
|
const TEMPLATE_DRIVEN_DIRECTIVES = [NgModel, NgModelGroup, NgForm];
|
5646
|
const REACTIVE_DRIVEN_DIRECTIVES = [FormControlDirective, FormGroupDirective, FormControlName, FormGroupName, FormArrayName];
|
5647
|
/**
|
5648
|
* Internal module used for sharing directives between FormsModule and ReactiveFormsModule
|
5649
|
*/
|
5650
|
class InternalFormsSharedModule {
|
5651
|
}
|
5652
|
InternalFormsSharedModule.decorators = [
|
5653
|
{ type: NgModule, args: [{
|
5654
|
declarations: SHARED_FORM_DIRECTIVES,
|
5655
|
exports: SHARED_FORM_DIRECTIVES,
|
5656
|
},] },
|
5657
|
];
|
5658
|
/**
|
5659
|
* @nocollapse
|
5660
|
*/
|
5661
|
InternalFormsSharedModule.ctorParameters = () => [];
|
5662
|
|
5663
|
/**
|
5664
|
* @license
|
5665
|
* Copyright Google Inc. All Rights Reserved.
|
5666
|
*
|
5667
|
* Use of this source code is governed by an MIT-style license that can be
|
5668
|
* found in the LICENSE file at https://angular.io/license
|
5669
|
*/
|
5670
|
/**
|
5671
|
* The ng module for forms.
|
5672
|
* \@stable
|
5673
|
*/
|
5674
|
class FormsModule {
|
5675
|
}
|
5676
|
FormsModule.decorators = [
|
5677
|
{ type: NgModule, args: [{
|
5678
|
declarations: TEMPLATE_DRIVEN_DIRECTIVES,
|
5679
|
providers: [RadioControlRegistry],
|
5680
|
exports: [InternalFormsSharedModule, TEMPLATE_DRIVEN_DIRECTIVES]
|
5681
|
},] },
|
5682
|
];
|
5683
|
/**
|
5684
|
* @nocollapse
|
5685
|
*/
|
5686
|
FormsModule.ctorParameters = () => [];
|
5687
|
/**
|
5688
|
* The ng module for reactive forms.
|
5689
|
* \@stable
|
5690
|
*/
|
5691
|
class ReactiveFormsModule {
|
5692
|
}
|
5693
|
ReactiveFormsModule.decorators = [
|
5694
|
{ type: NgModule, args: [{
|
5695
|
declarations: [REACTIVE_DRIVEN_DIRECTIVES],
|
5696
|
providers: [FormBuilder, RadioControlRegistry],
|
5697
|
exports: [InternalFormsSharedModule, REACTIVE_DRIVEN_DIRECTIVES]
|
5698
|
},] },
|
5699
|
];
|
5700
|
/**
|
5701
|
* @nocollapse
|
5702
|
*/
|
5703
|
ReactiveFormsModule.ctorParameters = () => [];
|
5704
|
|
5705
|
/**
|
5706
|
* @license
|
5707
|
* Copyright Google Inc. All Rights Reserved.
|
5708
|
*
|
5709
|
* Use of this source code is governed by an MIT-style license that can be
|
5710
|
* found in the LICENSE file at https://angular.io/license
|
5711
|
*/
|
5712
|
/**
|
5713
|
* @module
|
5714
|
* @description
|
5715
|
* This module is used for handling user input, by defining and building a {@link FormGroup} that
|
5716
|
* consists of {@link FormControl} objects, and mapping them onto the DOM. {@link FormControl}
|
5717
|
* objects can then be used to read information from the form DOM elements.
|
5718
|
*
|
5719
|
* Forms providers are not included in default providers; you must import these providers
|
5720
|
* explicitly.
|
5721
|
*/
|
5722
|
|
5723
|
/**
|
5724
|
* @license
|
5725
|
* Copyright Google Inc. All Rights Reserved.
|
5726
|
*
|
5727
|
* Use of this source code is governed by an MIT-style license that can be
|
5728
|
* found in the LICENSE file at https://angular.io/license
|
5729
|
*/
|
5730
|
/**
|
5731
|
* @module
|
5732
|
* @description
|
5733
|
* Entry point for all public APIs of the forms package.
|
5734
|
*/
|
5735
|
|
5736
|
// This file only reexports content of the `src` folder. Keep it that way.
|
5737
|
|
5738
|
/**
|
5739
|
* Generated bundle index. Do not edit.
|
5740
|
*/
|
5741
|
|
5742
|
export { AbstractControlDirective, AbstractFormGroupDirective, CheckboxControlValueAccessor, ControlContainer, NG_VALUE_ACCESSOR, COMPOSITION_BUFFER_MODE, DefaultValueAccessor, NgControl, NgControlStatus, NgControlStatusGroup, NgForm, NgModel, NgModelGroup, RadioControlValueAccessor, FormControlDirective, FormControlName, FormGroupDirective, FormArrayName, FormGroupName, NgSelectOption, SelectControlValueAccessor, SelectMultipleControlValueAccessor, CheckboxRequiredValidator, EmailValidator, MaxLengthValidator, MinLengthValidator, PatternValidator, RequiredValidator, FormBuilder, AbstractControl, FormArray, FormControl, FormGroup, NG_ASYNC_VALIDATORS, NG_VALIDATORS, Validators, VERSION, FormsModule, ReactiveFormsModule, InternalFormsSharedModule as ɵba, REACTIVE_DRIVEN_DIRECTIVES as ɵz, SHARED_FORM_DIRECTIVES as ɵx, TEMPLATE_DRIVEN_DIRECTIVES as ɵy, CHECKBOX_VALUE_ACCESSOR as ɵa, DEFAULT_VALUE_ACCESSOR as ɵb, AbstractControlStatus as ɵc, ngControlStatusHost as ɵd, formDirectiveProvider as ɵe, formControlBinding as ɵf, modelGroupProvider as ɵg, NgNoValidate as ɵbf, NUMBER_VALUE_ACCESSOR as ɵbb, NumberValueAccessor as ɵbc, RADIO_VALUE_ACCESSOR as ɵh, RadioControlRegistry as ɵi, RANGE_VALUE_ACCESSOR as ɵbd, RangeValueAccessor as ɵbe, formControlBinding$1 as ɵj, controlNameBinding as ɵk, formDirectiveProvider$1 as ɵl, formArrayNameProvider as ɵn, formGroupNameProvider as ɵm, SELECT_VALUE_ACCESSOR as ɵo, NgSelectMultipleOption as ɵq, SELECT_MULTIPLE_VALUE_ACCESSOR as ɵp, CHECKBOX_REQUIRED_VALIDATOR as ɵs, EMAIL_VALIDATOR as ɵt, MAX_LENGTH_VALIDATOR as ɵv, MIN_LENGTH_VALIDATOR as ɵu, PATTERN_VALIDATOR as ɵw, REQUIRED_VALIDATOR as ɵr };
|
5743
|
//# sourceMappingURL=forms.js.map
|