I have an Angular application where I retrieve data when the user clicks a button:
getJobNotes() {
this.jobNoteService.getJobNotes()
.subscribe(
result => {
this.jobNotes = result.jobNotes;
}
);
}
I would like to scroll into view an element that has a specific job note Id, ie, this may be the 5th element in a list of 10 as an example.
I have tried the following:
this.selectedJobNoteId = result.selectedJobNoteId;
let el = document.getElementById(this.selectedJobNoteId);
el.scrollIntoView();
in this case my 'el' variable is undefined.
In my html I am setting the ID correctly:
<li *ngFor="let jobNote of jobNotes" id="{{jobNote.jobNoteId}}">
I have confirmed that the ID is set, and if I run document.getElementById with the correct ID in the chrome console then I get back the element - I suspect the issue is that the elements are dynamically created?