I have created the following validation function:
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);
};
}
When I hook it to the control like this:
control: ['', this.passwordValid.bind(this)]
It never changes control validaiton to 'valid'. It is always invalid. What am I doing wrong?