Hello I have an input in my application which fires on every stroke but I want some delay so for eg. trigger my search function after 1 sec so that it doesn't send multiple requests
My Html Code
<input id="musicsearch"
  (input)="onSearchChange($event.target.value)"  
  ng-model-options="{debounce:1000}" 
  class="form-control mr-sm-2"style="width: 100%;"
  type="text"placeholder="Search">
component.ts (which handles change)
 onSearchChange(searchValue : string ) {    
    this.router.navigate(['/search', searchValue]);      
  }
I am new to angular I can't find solution for my problem, I want to trigger this when user stop typing in input
  private modelChanged: Subject<string> = new Subject<string>();
  private subscription: Subscription;
  debounceTime = 500;
  ngOnInit(): void {
    this.subscription = this.modelChanged
      .pipe(
        debounceTime(this.debounceTime),
      )
      .subscribe(() => {
        this.functionToBeCalled();
      });
  }
  functionToBeCalled() {
    console.log('Called After 500ms');
  }
  inputChanged() {
    this.modelChanged.next("Akshay Is Awesome")
  }
  ngOnDestroy(): void {
    this.subscription.unsubscribe();
  }
html file 
<input type="text" (keydown)="inputChanged()">
Try This Thanks me later :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With