Last active
April 28, 2016 19:56
-
-
Save chenkie/2fa24c1f4a9ef5ebe24715c4fa012d57 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Http, HTTP_PROVIDERS} from 'angular2/http'; | |
import {Injector} from 'angular2/core' | |
import {Control} from 'angular2/common'; | |
import 'rxjs/Rx'; | |
export class UsernameEmailValidator { | |
constructor() {} | |
static checkUser(control: Control) { | |
let injector = Injector.resolveAndCreate([HTTP_PROVIDERS]); | |
var http = injector.get(Http); | |
control.valueChanges | |
.debounceTime(500) | |
.flatMap(value => http.post('http://localhost:3000/api/users/check', JSON.stringify({ username: value }))) | |
.subscribe( | |
data => { | |
return null; | |
}, | |
error => { | |
return {'usernameTaken': true}; | |
} | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment