feat(forms): introduce AsyncValidator interface (#13483)

Closes #13398
This commit is contained in:
Dzmitry Shylovich
2017-02-21 03:26:51 +03:00
committed by Victor Berchet
parent d6a58f9f70
commit 551fe50ebd
12 changed files with 43 additions and 25 deletions

View File

@ -12,6 +12,7 @@ import {AbstractControl, FormArray, FormControl, FormGroup, Validators} from '@a
import {Observable} from 'rxjs/Observable';
import {normalizeAsyncValidator} from '../src/directives/normalize_validator';
import {AsyncValidator} from '../src/directives/validators';
import {EventEmitter} from '../src/facade/async';
export function main() {
@ -23,10 +24,11 @@ export function main() {
};
}
class AsyncValidatorDirective {
class AsyncValidatorDirective implements AsyncValidator {
constructor(private expected: string, private error: any) {}
validate(c: any): {[key: string]: any;} {
validate(c: any): Observable < { [key: string]: any; }
> {
return Observable.create((obs: any) => {
const error = this.expected !== c.value ? this.error : null;
obs.next(error);