title: Angular 7.x.x easiest way to scroll to a fragment?
body: <p>In the past two days i've been diggin through the internetz about scrolling a fragment into view with angular.</p>
  
  <p>Let's say we have a static webpage with a bunch of id-s that act as fragments. And has a side nav-bar to navigate through the fragments with links.</p>
  
  <p>I've tried Router anchorScroll simply adding <a href="https://medium.com/lacolaco-blog/introduce-router-scroller-in-angular-v6-1-ef34278461e9" rel="noreferrer">this</a> to the module is doing nothing for me. It just gives you the fragment in the URL but no scrolling.</p>
  
  <p>I've tried viewportScroller. The main issue with this is it's not working for the first time (eg.: you are redirected to this static page with to a desired fragment, but the scrolling is not happening, if you've been on this same page and repeat the process, it works, if you click on the link at the side nav-bar that has the same url as you are visiting:
  <code>([foo]/[bar]#[fragment])</code> it's not working either since no navigation has changed.</p>
  
  <p>extra options used for router:</p>
  
  <pre><code>const routerOptions: ExtraOptions = {
    useHash: false,
    anchorScrolling: 'enabled',
    scrollPositionRestoration: 'enabled',
    onSameUrlNavigation: 'reload'
  };
  </code></pre>
  
  <p>ps.: useHash: true makes no change what so ever.</p>
  
  <p>viewportScroller inside ngOnInit:</p>
  
  <pre><code>this.viewportScroller.setOffset([0, 64]);
  this.viewportScroller.setHistoryScrollRestoration('auto');
  
  this.router.events.pipe(filter(element =&gt; element instanceof Scroll)).subscribe((element: any) =&gt; {
    console.log(element)
    this.viewportScroller.scrollToAnchor(element.anchor);
  });
  </code></pre>
  
  <p>What is the easiest way to scroll to a fragment WITHOUT!!! using this:</p>
  
  <pre><code>ngOnInit() {
    this.route.fragment.subscribe((fragment: string) =&gt; { 
      if (fragment &amp;&amp; document.getElementById(fragment) != null) {
        document.getElementById(fragment).scrollIntoView({ behavior: "smooth" });
      }
    });
  }
  </code></pre>
  
  <p>b/c with that it works every time but it's not TS, as we use TS in our company's projects.</p>
  
  <p>Help me out please</p>