forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 1
/
abstract_form_group_directive.ts
69 lines (53 loc) · 1.71 KB
/
abstract_form_group_directive.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {OnDestroy, OnInit} from '@angular/core';
import {FormGroup} from '../model';
import {ControlContainer} from './control_container';
import {Form} from './form_interface';
import {composeAsyncValidators, composeValidators, controlPath} from './shared';
import {AsyncValidatorFn, ValidatorFn} from './validators';
/**
* This is a base class for code shared between `NgModelGroup` and `FormGroupName`.
*
* @stable
*/
export class AbstractFormGroupDirective extends ControlContainer implements OnInit, OnDestroy {
/** @internal */
_parent: ControlContainer;
/** @internal */
_validators: any[];
/** @internal */
_asyncValidators: any[];
ngOnInit(): void {
this._checkParentType();
this.formDirective !.addFormGroup(this);
}
ngOnDestroy(): void {
if (this.formDirective) {
this.formDirective.removeFormGroup(this);
}
}
/**
* Get the `FormGroup` backing this binding.
*/
get control(): FormGroup { return this.formDirective !.getFormGroup(this); }
/**
* Get the path to this control group.
*/
get path(): string[] { return controlPath(this.name, this._parent); }
/**
* Get the `Form` to which this group belongs.
*/
get formDirective(): Form|null { return this._parent ? this._parent.formDirective : null; }
get validator(): ValidatorFn|null { return composeValidators(this._validators); }
get asyncValidator(): AsyncValidatorFn|null {
return composeAsyncValidators(this._asyncValidators);
}
/** @internal */
_checkParentType(): void {}
}