fix(forms): fully support rebinding form group directive (#11051)

This commit is contained in:
Kara
2016-08-25 14:37:57 -07:00
committed by Victor Berchet
parent d7c82f5c0f
commit 515ff61fcb
4 changed files with 194 additions and 10 deletions

View File

@ -67,6 +67,12 @@ export function setUpControl(control: FormControl, dir: NgControl): void {
dir.valueAccessor.registerOnTouched(() => control.markAsTouched());
}
export function cleanUpControl(control: FormControl, dir: NgControl) {
dir.valueAccessor.registerOnChange(() => _noControlError(dir));
dir.valueAccessor.registerOnTouched(() => _noControlError(dir));
if (control) control._clearChangeFns();
}
export function setUpFormContainer(
control: FormGroup | FormArray, dir: AbstractFormGroupDirective | FormArrayName) {
if (isBlank(control)) _throwError(dir, 'Cannot find control with');
@ -74,6 +80,10 @@ export function setUpFormContainer(
control.asyncValidator = Validators.composeAsync([control.asyncValidator, dir.asyncValidator]);
}
function _noControlError(dir: NgControl) {
return _throwError(dir, 'There is no FormControl instance attached to form control element with');
}
function _throwError(dir: AbstractControlDirective, message: string): void {
let messageEnd: string;
if (dir.path.length > 1) {