fix(forms): check if registerOnValidatorChange exists on validator before trying to invoke it (#12801)

closes #12593
This commit is contained in:
Victor Berchet 2016-11-10 16:20:59 -08:00 committed by GitHub
parent 458ca7112a
commit ef881475e9
1 changed files with 13 additions and 3 deletions

View File

@ -77,9 +77,19 @@ export function setUpControl(control: FormControl, dir: NgControl): void {
export function cleanUpControl(control: FormControl, dir: NgControl) { export function cleanUpControl(control: FormControl, dir: NgControl) {
dir.valueAccessor.registerOnChange(() => _noControlError(dir)); dir.valueAccessor.registerOnChange(() => _noControlError(dir));
dir.valueAccessor.registerOnTouched(() => _noControlError(dir)); dir.valueAccessor.registerOnTouched(() => _noControlError(dir));
dir._rawValidators.forEach((validator: Validator) => validator.registerOnValidatorChange(null));
dir._rawAsyncValidators.forEach( dir._rawValidators.forEach((validator: any) => {
(validator: Validator) => validator.registerOnValidatorChange(null)); if (validator.registerOnValidatorChange) {
validator.registerOnValidatorChange(null);
}
});
dir._rawAsyncValidators.forEach((validator: any) => {
if (validator.registerOnValidatorChange) {
validator.registerOnValidatorChange(null);
}
});
if (control) control._clearChangeFns(); if (control) control._clearChangeFns();
} }