I've created an angular component that serves as a tab within a for loop on my HTML page:
...
<ng-container *ngFor="let tabData of data$ | async;">
<tab-component
id="{{ tabData.id }}"
name="{{ tabData.name }}"
>
</tab-component>
</ng-container>
<child-component [selectedData]="selectedData"></child-component>
Here is the relevant information from my .ts file:
public data$: Observable<Data[]>
public selectedData: Data
ngOnInit() {
this.data$ = this.service.getAllData();
}
ngAfterContentInit() {
this.data$.subscribe(items => this.selectedData = items[0])
}
My goal is to have the first tab always display the selectedData by default when the page loads (element 0 in the array). I want the selectedData to dynamically update when the user clicks on a tab or uses the right/left arrow keys, and have this updated value passed to the child component. However, I've been struggling to achieve this as the value of selectedData in the child component always seems to be undefined.
If anyone has any suggestions or solutions on how I could make this work, I would greatly appreciate the help!