static validateByService(asyncValidatorService: AbstractAsyncValidatorService): AsyncValidatorFn {
const validityNotifier = new Subject<any>();
return (control: AbstractControl): Observable<ValidationResult|null> => {
if (typeof control.valueChanges === 'undefined') {
return Observable.of({});
};
validityNotifier.next();
return control.valueChanges
.debounceTime(AsyncValidatorDirective.DEBOUNCE_INTERVAL)
.takeUntil(validityNotifier)
.take(1)
.switchMap((value: any) => asyncValidatorService.validate(value));
};
}
constructor() { }
validate(control: AbstractControl): Observable<ValidationResult> {
return AsyncValidatorDirective.validateByService(this.asyncValidatorService)(control);
// Here getting error.
}
错误讯息:
/src/app/validators/async-validator/async-validator.directive.ts (78,12): Type 'Promise<ValidationErrors> | Observable<ValidationErrors>' is not assignable to type 'Observable<any>'.
Type 'Promise<ValidationErrors>' is not assignable to type 'Observable<any>'.
Property '_isScalar' is missing in type 'Promise<ValidationErrors>'.
由于AOT编译问题,我不得不升级我的angular4。现在编译上面错误正在终端中抛出。