Kelem February 2016

How to trigger validation input after debounce time in Angular2?

I have a form with a "name" control.

<div class="field">
  <input ngControl="name">
  <p *ngIf="name.pending">
    Fetching data from the server...
  <div *ngIf="!name.valid && !name.pending"
    class="ui error message">Name is not valid</div>

The control is built with FormBuilder like this : = fb.control('', null, this.characterNameValidator.bind(this));

and I created a validator :

characterNameValidator(control: Control) {
    let q = new Promise((resolve, reject) => {
        setTimeout(() => {
            if (this._characterService.isCharacterNameAlreadyExists(control.value)) {
                resolve({nameCharacterAlreadyExistsError: true});
            } else {
        }, 1000)

    return q;

On each keystroke, my validator is called. I'm looking for a way to call the validator only after a debounce time.

I try with valueChanges(), but I understand only if I call a specific service but not in the case of validation.


Is it a good idea to manage validation manually to achieve my problem ? I don't put a validator in my control but I set errors manually on valueChanges. = fb.control(''); => {
  this.characterNameValidator( => {


Günter Zöchbauer February 2016

See for a related open issue.

If you pass a reference to the control to the validator you could use something like



Post Status

Asked in February 2016
Viewed 3,998 times
Voted 8
Answered 1 times


Leave an answer