Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Scrolled) event triggered on multiple angular routes #388

Open
patilsagar28290 opened this issue Sep 17, 2021 · 3 comments
Open

(Scrolled) event triggered on multiple angular routes #388

patilsagar28290 opened this issue Sep 17, 2021 · 3 comments

Comments

@patilsagar28290
Copy link

In my site, I have two tabs like 'Active Users" and "Left users" (two separate routes). Infinite scroll is working fine when we are on first tab, but when we switched to another tab or route. First tabs (previous routes) scrolled events gets triggered.

Expected Behavior

Scrolled event should be triggered for active route. It should not trigger for visited route

Actual Behavior

When we change route previous routes scrolled event handler gets called

Steps To Reproduce / Demo (if applicable)

@gchokeen
Copy link

I got same issue! Is there any work around ?

@patilsagar28290
Copy link
Author

@gchokeen Below workaround helped me, you can try as well

On route changed, maintain one flag to disable scroll effect.
this._router.events
.pipe(filter((event) => event instanceof RoutesRecognized))
.subscribe((event: RoutesRecognized) => {
this.routeChanged = event.url.replace('/', '') !== 'home';
this._changeDetectionRef.detectChanges();
})

In html file, set infiniteScrollDisabled attribute
<div
infiniteScroll
[infiniteScrollDistance]="infiniteScrollDistance"
[infiniteScrollDisabled]="routeChanged"
(scrolled)="onScrollDown()"
>

  Hopefully this will work for you as well.

@gchokeen
Copy link

@patilsagar28290 Excellent thanks it worked perfectly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants