The cancel function in lodash's debounce feature does not successfully halt the execution of the

In my angular application, I have implemented http calls on each modelChange event with the help of lodash's _.debounce(). However, I'm facing an issue where I am unable to cancel these calls after the initial successful execution of debounce.

  modelChangeEvent(item):void {
   const _this = this;
   let debounceObj = _.debounce(function(){
     _this.makeHttpCall(item);
     debounceObj.cancel();
    },600);
  debounceObj();
  }

https://lodash.com/docs/4.17.15#debounce

Answer №1

Utilized Rxjs with debounceTime() and distinctUntilChanged() methods

inputDetector: any = new Subject();

ngOnInit(){
  this.inputDetector.pipe(debounceTime(400), distinctUntilChanged()).subscribe(value => {
    this.fetchDataFromServer(value)
  })
}

updateModel(item): void {
  this.inputDetector.next(item);
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to reverse the direction of the slider's track?

Our goal in the design is for users to select a value between 0 and 20, with the selected range being that value up to 20. Currently, Angular Material slider component highlights values from 0 up to the selected value as the active track. Is there a way to ...

Enable Angular Server-Side Rendering for seamless navigation without refreshing the page when clicking

Can Angular SSR be utilized to navigate between pages without requiring a reload? ...

Saving JSON format in VueX State Management

I'm relatively new to using Vue/VueX and I am exploring methods for storing JSON data in the VueX state. Initially, it seemed like a simple task: state { jsonthing: { ... } } However, I encountered an issue where getters return an Observer type ins ...

Angular 5 Routerlink and button not working in IE and Firefox due to lack of response

Recently, I created a new Angular 5 CLI application and developed a navmenu component for the top section of the app. It functions flawlessly in Edge and Chrome - clicking on menu items follows the specified route in app.module.ts as expected. However, whe ...

The utilization of `ngSwitch` in Angular for managing and displaying

I am brand new to Angular and I'm attempting to implement Form Validation within a SwitchCase scenario. In the SwitchCase 0, there is a form that I want to submit while simultaneously transitioning the view to SwitchCase 1. The Form Validation is fun ...

Obtain text output from an Observable

After retrieving a String from the backend: String value = "{I am here}"; In my service method: getValue(): Observable<String> { return this.http.get<String>(this.myURL); } In my component, I am subscribing to this method: String myM ...

An error occurred in TypeScript when trying to use the useState function with a string type. The ReferenceError indicates that

import React, { FunctionComponent, useState, useEffect } from 'react' const SearchBar: FunctionComponent = () => { const [searchValue, setSearchValue] = useState<string>('') const [isSuggestionOpen, setIsSuggestionO ...

How to dynamically customize styling on md-tab in Angular2-material?

Styling material design components can be challenging, especially when trying to dynamically set styles on an md-tab based on its active or archived state. I'm looking to make the tab header text italic and change its color to indicate whether it is a ...

Awaiting a response from the http.get() function

Currently, I am in the process of creating a login feature using Angular and Ionic 2. This feature aims to verify if the user is registered in the database through a PHP server and return a user ID. However, I have encountered an issue with the asynchronou ...

Typescript Error: Trying to access a property that is undefined

I am a beginner in typescript and believe that the issue I am facing is related to typescript. Currently, I am working on an Ionic app where I have a function setwall() being called from home.html. The setwall() function is defined in home.ts. However, whe ...

Alter the color of the mat-select once it has been chosen

Is there a way to keep the same color for mat-select focus even after selection? I have checked the documentation but couldn't find any information on this. <mat-form-field> <mat-label>Choose an option</mat-label> <mat-select ...

Npm Installation Issue (Dependency Resolution Failure)

Whenever I attempt to execute npm install, I encounter the following error: npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree npm ERR! npm ERR! While resolving: <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfe ...

Avoiding repeated observable executions

My current task involves implementing a screen that displays constantly changing data from an API. To achieve this, I have utilized the repeatWhen() method on the observable generated by the API call for polling purposes. Additionally, I need to make an ex ...

Strange occurrences with HTML image tags

I am facing an issue with my React project where I am using icons inside img tags. The icons appear too big, so I tried adjusting their width, but this is affecting the width of other elements as well. Here are some screenshots to illustrate: The icon wit ...

Instructions for adding a prefix of +6 in the input field when the user clicks on the text box

Recently, I've been utilizing Angular Material elements for input fields which can be found at this link. An interesting feature that I would like to implement is automatically adding '+6' when a user clicks on the phone number field. You ...

Error encountered during the production build of Angular 2. No issues reported during development phase

During development, I can successfully run the code below. However, when I deploy to production, I encounter the following errors: node_modules/@angular/common/src/pipes/async_pipe.d.ts(39,38): error TS2304: Cannot find name 'Promise'. node_modu ...

What might be the reason behind Array concatenation causing an issue in TypeScript?

I am relatively new to TypeScript and recently encountered an issue while working with classes. class DataStorage { private data:string[] = []; addItem(item: string){ this.data.push(item); } removeItem(item: string){ ...

Having trouble integrating SVG icons into my Angular project

I'm encountering an issue with adding icons that I've designed in Figma to my web application. Some of the icons are displaying correctly while others are not. Here is the code snippet I am using to add the icons: .dx-icon-info { mask-image: ...

Guide on integrating Amazon S3 within a NodeJS application

Currently, I am attempting to utilize Amazon S3 for uploading and downloading images and videos within my locally running NodeJS application. However, the abundance of code snippets and various credential management methods available online has left me fee ...

Angular Universal involves making two HTTP calls

When using Angular Universal, I noticed that Http calls are being made twice on the initial load. I attempted to use transferState and implemented a caching mechanism in my project, but unfortunately, it did not resolve the issue. if (isPlatf ...