title: Angular5 - Scrolling to anchor
body: <p>I am trying to do a scroll to an anchor when I redirect to a new page. I have tried different things but without success. Now it scrolls down but it's not showing the whole HTML element I need, it shows only the header of the element.
  Here is the redirect to the new page</p>
  <pre><code>this.router.navigate(['/controllo/' + result.id], {fragment: 'assegnazioneContatto'});
  </code></pre>
  <p>And here is how I scroll to the element</p>
  <pre><code>ngOnInit() {
      this.routeParams.fragment.subscribe(fragment =&gt; {
          if(window.document.getElementById(fragment)) {
            this.fragment = fragment; 
            window.document.getElementById(this.fragment).scrollIntoView();
         }
        });
  }
  </code></pre>
  <p>Here is the HTML element</p>
  <pre><code>&lt;div class=&quot;row&quot; [hidden]=&quot;!showAssegnazioneContatto()&quot; id=&quot;assegnazioneContatto&quot;&gt;&lt;/div&gt;
  </code></pre>
  <p>What am I doing wrong? I have seen other questions here in stackoverflow but I haven't found any solution.</p>
  <p>PS. If I run the code in the console it works fine</p>