I fetch a collection of json objects (each for a tab) from php backend then try to display each in a tab
<ion-tabs #myTabs>
<ion-tab *ngFor="let tab of userGroups" [root]="page" rootParams="{{tab.id}}" tabTitle="{{tab.group}}" tabIcon="pulse"></ion-tab>
</ion-tabs>
(page - the same one for each, only params passed are different)
The problem is the tabbar is invisible (when you hover over it, the mouse cursor changes so it’s physically there). When you click, the whole tabbar becomes visible and the clicked tab is selected - then all works as expected.
My observations:
- When you add at least one static tab, all the other dynamic are visible (the static is selected).
- Inspecting the page with Chrome tools shows that div containing the tabs has only ‘tabbar’ class (opacity:0). When you click one of the tabs, class of ‘show-tabbar’ is added.
- Trying to force any tab to be selected after displaying them has no effect (selectedIndex=“0”, selecting the tab programatically by referencing the parent tabs has also no effect)
- When you hardcode the objects array in tabs component .ts file, all works - problem persists only when you fetch it from a server like so:
ionViewDidLoad() { this.api.getGroupsList() .subscribe( data => { this.userGroups = data; }, err => this.helpers.presentAlert( err ) //show modal with err ); }
Conclusion is that you cannot force a selection on tabs generated dynamically in *ngFor loop. As a consequence, no selection leaves the div container with only ‘tabbar class’ (ie opacity:0)
Have you run into similar issues?
ps. As a workaround for now I’ve added “div.tabbar {opacity:1;}” to tabs.scss (but still there’s no default selection).