我无法让它与SelectedIndexValueAccessor
指令一起使用,所以我调整了另一个解决方案,希望有人觉得它有用:
主页.html:
<ActionBar [title]="tabs[tabId].title" class="action-bar"></ActionBar>
<GridLayout>
<TabView #tabview (selectedIndexChanged)="tabIndexChanged($event)">
<StackLayout *tabItem="tabs[0]" >
<first-tabview-item></first-tabview-item>
</StackLayout>
<StackLayout *tabItem="tabs[1]">
<second-tabview-item></second-tabview-item>
</StackLayout>
<StackLayout *tabItem="tabs[2]">
<third-tabview-item></third-tabview-item>
</StackLayout>
</TabView>
</GridLayout>
mainPage.component.ts:
import { Component, OnInit } from "@angular/core";
@Component({
selector: "main-page",
moduleId: module.id,
templateUrl: "./mainPage.html",
styleUrls: ["./mainPage-common.css", "./mainPage.css"],
})
export class MainPageComponent implements OnInit {
private tabs: object[];
private tabId: number;
constructor() { }
public ngOnInit(): void {
this.tabs = [
{
title: 'Tab 1 title',
iconSource: '~/images/tab1.png',
},
{
title: 'Tab 2 title',
iconSource: '~/images/tab2.png',
},
{
title: 'Tab 3 title',
iconSource: '~/images/tab3.png',
},
];
}
public tabIndexChanged(event: any) {
this.tabId = event.newIndex;
console.log(`Selected tab index: ${event.newIndex}`);
}
}