fix(forms): async validator cancels previous subscription when input has changed (#13222)

Fixes #12709
Fixes #9120
Fixes #10074
Fixes #8923

PR Close #13222
This commit is contained in:
Dzmitry Shylovich
2016-12-04 01:17:09 +03:00
committed by Miško Hevery
parent 22058298d3
commit 6c7300c7de
2 changed files with 26 additions and 3 deletions
+1 -1
View File
@@ -384,6 +384,7 @@ export abstract class AbstractControl {
this._updateValue();
if (this.enabled) {
this._cancelExistingSubscription();
this._errors = this._runValidator();
this._status = this._calculateStatus();
@@ -417,7 +418,6 @@ export abstract class AbstractControl {
private _runAsyncValidator(emitEvent: boolean): void {
if (this.asyncValidator) {
this._status = PENDING;
this._cancelExistingSubscription();
const obs = toObservable(this.asyncValidator(this));
this._asyncValidationSubscription =
obs.subscribe({next: (res: {[key: string]: any}) => this.setErrors(res, {emitEvent})});