Dynamic tabs in TabView nativescript

筅森魡賤 提交于 2019-12-23 04:11:52

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!