0

I'm having problem with scrolling scrollbar to the bottom. It works on load correctly when on ngAfterViewInit.

When I add new message it doesn't trigger the scroll, but after adding the second message, it scrolls to the first message. So it looks like I need an delay or something.

@ViewChild(PerfectScrollbarComponent, {static: true}) scrollbar?: PerfectScrollbarComponent;


scrollToBottom(): void {
    this.scrollbar.directiveRef.scrollToBottom(0, 200);
 }

I created a Stackblitz for that: StackBlitz

Whistler
  • 1,897
  • 4
  • 29
  • 50
  • 1
    [This stack overflow answer should help! Best of luck](https://stackoverflow.com/a/11715670/10783165) – Tony M Jun 27 '19 at 16:16

1 Answers1

1

Wrap it with setTimeout:

setTimeout(() => {
  this.scrollToBottom();
});
Maihan Nijat
  • 9,054
  • 11
  • 62
  • 110