I'm trying to implement key board navigation on a list of components present inside ViewContainerRef
, without knowing how many components are actually present.
Current approach: Right now while adding components in ViewContainerRef, I'm storing component index inside view and ComponentRef together as a object in a list i.e:
{ component : ComponentRef<any>, index: number }
I'm getting index by doing indexOf
on ViewContainerRef
.
For key board navigation , I'm listening to events and traversing through the list I created I above and keeping track of what's currently selected component.
Can this be done in a better way?