我发现这个tutorial可以进行异步验证。这不再适用于RC3(Reactive Froms)。
如何在此进行异步验证?
this.username = new FormControl( '', [ <any>Validators.required, <any>ProfileValidator.usernameTaken ]);
...
class ProfileValidator {
static usernameTaken(control: FormControl): Promise<{[key:string]:boolean}> {
let q = new Promise((resolve, reject) => {
setTimeout(() => {
resolve(null);
}, 1000)
});
return q;
}
}
FormControl始终无效......
答案 0 :(得分:0)
表单控件的签名应该像第三个arg那样具有异步验证器:
new FormControl( '',
[ <any>Validators.required], //sync
[<any>ProfileValidator.usernameTaken ] //async
);