username works!

This commit is contained in:
programmingPug
2018-04-24 09:16:54 -04:00
parent 2be5ab498f
commit 5db5cf17e1
3 changed files with 43 additions and 37 deletions

View File

@@ -1,31 +1,35 @@
import { AbstractControl } from '@angular/forms';
import { Injectable } from '@angular/core';
import { FormControl } from '@angular/forms';
import { RegistrationService } from '../registration.service';
export class ValidateUserName{
constructor(
private RS: RegistrationService
){ }
validateUserName( control: AbstractControl ){
//var RS = new RegistrationService(null);
/*
this.registrationService2.validateUserName( control.value ).subscribe( data => {
console.log( data );
if( control.value != data.username ){
return{
validUserName: true
};
}
return null;
});
*/
}
}
@Injectable()
export class UsernameValidator {
debouncer: any;
constructor(private registrationService: RegistrationService){
}
checkUsername(control: FormControl): any {
clearTimeout(this.debouncer);
return new Promise(resolve => {
this.debouncer = setTimeout(() => {
this.registrationService.validateUserName(control.value).subscribe((res) => {
if(res.ok){
resolve(null);
}
}, (err) => {
resolve({'usernameInUse': true});
});
}, 1000);
});
}
}