Project

General

Profile

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