Q:

Angular5 ngAfterviewchecked , scrollIntoView()

on page load, it should scroll down to a specific div I did that using below function, but the issue is after page load, its giving me issues while scroll up and down, the below function doesn't let me scroll up and down properly. 
ngAfterViewChecked(): void{

    if (this.primary){
      setTimeout(() => {
    this.scrollTo.nativeElement.scrollIntoView();
      },100);
  }
  }

I didn't use timeout, so scroll was not moving from the div position. It was fixed there. But once I used setTimeout it start moving but still gives me issue. I just want to use scrollIntoView on page load.

A:

use a variable to prevent the function from being called multiple time
isStarting:boolean=true;
ngAfterViewChecked(): void{

    if (this.primary && this.isStarting){
      setTimeout(() => {
    this.scrollTo.nativeElement.scrollIntoView();
this.isStarting=false;
      },100);
  }
  }

