0

I'd like to scroll to a particular element on an event (onEmitKennlinie()), but it doesnt't work. Why is the result (var element) of "document.getElementById()" Null?

Here is my code:

onEmitKennlinie(isKennlinie: boolean) {
  if(isKennlinie){ 
    var element = document.getElementById('Kennlinien_Anfang') as HTMLElement;
    console.log("ELEMENT ", element);
    if(element) {
      element.scrollIntoView(); // scroll to a particular element
    }
  }
}

This is my HTML:

<div id="Kennlinien_Anfang">
   <app-schrauberdaten-kennliniengrafik
      (Report)="onReportKennlinien($event)">
   </app-schrauberdaten-kennliniengrafik>
</div>


Eyeslandic
  • 12,640
  • 12
  • 34
  • 47
  • This code works for me, when in the lifecycle of the component are you calling this method? – Eyeslandic Jan 06 '21 at 10:12
  • This might also help, a more "Angular-ly" solution. https://stackoverflow.com/questions/47616843/how-to-call-scrollintoview-on-an-element-in-angular-2 – Eyeslandic Jan 06 '21 at 10:16

0 Answers0