问题
Is it possible to create tabs dynamically for a tabview in nativescript?
The following example is in the documentation of nativescript
<TabView selectedIndex="0" (selectedIndexChange)="onIndexChanged($event)" sdkExampleTitle sdkToggleNavButton>
<StackLayout *tabItem="{title: 'NativeScript'}">
<Label text="NativeScript" class="m-15 h2 text-left" color="blue"></Label>
<ScrollView>
<Label [text]="content" textWrap="true" class="m-15"></Label>
</ScrollView>
</StackLayout>
<StackLayout *tabItem="{title: 'Icon'}">
<Image class="m-t-30 m-b-15" src="res://icon" width="80" height="80"></Image>
<Label text="NativeScript" textWrap="true" class="h2 m-x-auto" color="blue"></Label>
</StackLayout>
</TabView>
and it does not allow me to use the ng for since the StackLayout element already has a directive that starts with *
回答1:
Yes you can ! use *ngFor
<TabView>
<ng-container *ngFor="let tab of tabList">
<StackLayout *tabItem="tab">
.....
</StackLayout>
</ng-container>
</TabView>
来源:https://stackoverflow.com/questions/47278128/dynamic-tabs-in-tabview-nativescript