3
我需要实现与github api的异步验证。我希望你能帮助我。Angular2用户名或电子邮件采取异步验证
export class UsernameValidator {
static usernameTaken(control: FormControl): Promise<ValidationResult> {
return new Promise((resolve, reject) => {
setTimeout(() => {
//How Can i use github Api like this:
// if (control.value === "this._http.get('http://api.github.com/users/'+this.username)")) {
if (control.value === "David") {
console.log('username taken')
resolve({"usernameTaken": true})
} else {
resolve(null);
};
}, 1000);
});
}
}
谢谢。
你让我很快乐!谢谢。它的作品非常酷 –
@AlexanderBorovoi请检查我的问题我有一个非常类似的情况http://stackoverflow.com/questions/40756441/custom-async-validation-not-working-when-returning-a-promise – Luther
可以你请在你的例子中添加一个去抖时间?我不希望每个按键发送http请求。 – Michalis