Update: I understand the desired outcome here. One approach is to create a middleman list and use that in your ngFor
loop. This allows you to easily switch between different lists by changing the reference of the intermediary list when needed.
export class ListPage {
transportationModes: string[] = ['car', 'train'];
carDetails: string[] = ['red', 'four wheels'];
trainDetails: string[] = ['fast', 'on tracks'];
selectedList: string[] = this.transportationModes;
selectItem(mode): void {
if (mode === 'car') {
this.selectedList = this.carDetails;
} else if(mode === 'train') {
this.selectedList = this.trainDetails;
} else {
this.selectedList = this.transportationModes;
}
}
}
Simply trigger the selectItem
function in your HTML code
<ion-list *ngIf="selectedList">
<ion-item *ngFor="let detail of selectedList" (click)="selectItem(detail)">
{{detail}}
</ion-item>
</ion-list>