Nativescript-angular: TabView doesn't work with ngFor

Created on 26 Feb 2016  路  2Comments  路  Source: NativeScript/nativescript-angular

I tried some code but they don't work:

<TabView> <StackLayout *ngFor="#tab of tabs; #i = index" *tabItem="{title: tab.text}"> content here </StackLayout> </TabView>
or
<TabView> <StackLayout *ngFor="#tab of tabs; #i = index"> <StackLayout *tabItem="{title: tab.text}"> content here </StackLayout> </StackLayout> </TabView>

Most helpful comment

Another working example with *ngFor syntax:

<TabView>
    <ng-container *ngFor="let tab of tabList">
        <StackLayout *tabItem="tab">
            <Label [text]="tab.title"></Label>
        </StackLayout>
    </ng-container>
</TabView>

All 2 comments

Sorry, I figured out a solution:

    <TabView >
         <template ngFor #tab [ngForOf]="tabs">
            <StackLayout *tabItem="{title: tab.text}">
                content here
            </StackLayout>
         </template>
    </TabView>

Another working example with *ngFor syntax:

<TabView>
    <ng-container *ngFor="let tab of tabList">
        <StackLayout *tabItem="tab">
            <Label [text]="tab.title"></Label>
        </StackLayout>
    </ng-container>
</TabView>
Was this page helpful?
0 / 5 - 0 ratings