Using lodash debounce in Angular2 & Typescript scroll not working Using lodash debounce in Angular2 & Typescript scroll not working angular angular

Using lodash debounce in Angular2 & Typescript scroll not working


I'm not familiar with lodash, but I think what you want is:

private debouncedOnScroll = _.debounce(() => this.onScrollDown(), 1500, {});@HostListener("window:scroll", [])onWindowScroll() {    this.debouncedOnScroll();}private onScrollDown() {    console.log("onScrollDown")}


Thanks to JB Nizet I could solve my need this is my approach:

1) Create function you want to debounce:

private projectsLoad(myParameter): void {   // function code here...};

2) Assign it to a field/member of the class:

private debounceProjectsLoad = _.debounce(    (myParameter) => this.projectsLoad(myParameter),    1500,    true);

3) Call the debounced field/meber when neeeded:

public loadProjectsGroup(myParameter: string): void {    this.debounceProjectsLoad(myParameter);}