Created
October 22, 2019 22:07
-
-
Save jugyo/d251fe99687b99ac49fab8cbcd47bf48 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
export class AppModule { | |
constructor(router: Router, viewportScroller: ViewportScroller) { | |
router.events.pipe(filter((e) => e instanceof Scroll)).subscribe((e: any) => { | |
if (e.position) { | |
// backward navigation | |
setTimeout(() => { | |
viewportScroller.scrollToPosition(e.position); | |
}, 100); | |
} else if (e.anchor) { | |
// anchor navigation | |
viewportScroller.scrollToAnchor(e.anchor); | |
} else { | |
// forward navigation | |
viewportScroller.scrollToPosition([0, 0]); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment