现在的代码为:
`
return new Promise((resolve) => {
if (!control.value) {
control.setErrors({namesUnion: true });
return resolve({namesUnion: true });
} else {
control.valueChanges.pipe(throttleTime(1000),first()).pipe(mergeMap((value) => this.getResult(value))).subscribe(
data => {
console.log('[NamesUnionValidator-Directive]result value: '+data);
control.setErrors(null);
return resolve(null);
},
error => {
let er:HttpErrorResponse = error as HttpErrorResponse;
console.log('[NamesUnionValidator-Directive]error status: '+er.status);
control.setErrors({namesUnion: true });
return resolve({namesUnion: true });
}
);
}
});
`
在输入框中输入:xiaofanku, 会发出9条请求,如下图:
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…