[英]Async Validator never resolves to true
我創建了以下驗證功能:
passwordValid(control:Control):{ [key: string]: any; } {
clearTimeout(this.timer);
if (control.value){
let q = new Promise((resolve) => {
this.timer = setTimeout(()=>{
this._http.post('/check', control.value)
.subscribe(
success=>{
resolve(null);
},
error=>{
resolve({'invalid': true});
})
},1000);
});
return Observable.fromPromise(q);
};
}
當我像這樣將其掛接到控件時:
control: ['', this.passwordValid.bind(this)]
它永遠不會將控制有效性更改為“有效”。 它總是無效的。 我究竟做錯了什么?
使用您的代碼,您將驗證器注冊為同步1(控件的第二個參數)。
對於異步的,您需要使用第三個參數:
control: ['', null, this.passwordValid.bind(this)]
本文可能使您感興趣:
異步驗證器應位於索引2
control: ['', null, this.passwordValid.bind(this)]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.