3

In Angular1, I was able to add add debounce time for ng-model.

In Angular2, we can detect changes on all input. Is it possible to have some debounce time on each input change.

From the following plunker example, http://plnkr.co/edit/JKYSek?p=preview, I type "hello world", but it reacts to every single key stroke.

Is it possible to have some delay on each change without any programming?

import { Directive, OnChanges } from "@angular/core";

@Directive({
  selector: '[my-directive]',
  inputs: [`myInput`]
}) 
export class MyDirective implements OnChanges {

  ngOnChanges(changes: {[key: string]: SimpleChange}) {
    console.log('changes :'+ changes.myInput.currentValue);
  }
}

enter image description here

1 Answer 1

3

Angular doesn't provide anything. It was discussed and there is an open issue AFAIR.

As workaround you can forward to an observable or use Observable.fromEvent() with debounce.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.