In my Angular 7 application, I have have over 5000 elements in a tree view. I need to access the DOM element that has been selected, so I can use something like scrollIntoView. Basically my pseudo code would look like this:
if selected element is not visible call scrollIntoView on the element Problem is, I need to call this every time the keyboard is pressed (arrows up and down). I have tried passing in the $event to find the previous element, next element, and so on, so I can simply call scrollIntoView() on that element, but I don't think that's a very good idea. It involves a lot of recursion (because the tree view is nested) and my HTML can never change (unless I update the code as well).
Is it possible to set ViewChild() based on a condition? That way I can simply do this.selectedElement.nativeElement.scrollIntoView() or something like that. Unless there's a better idea?
ngFor