【发布时间】:2018-03-07 09:25:11
【问题描述】:
我在我的应用程序的主页上设计了一个元素,当点击该元素时,它会更改活动选项卡。
我曾经做过以下事情:
events.subscribe('change-tab', (tab, filterOnSport) => {
console.log('TabsPage#constructor - change-tab event received with params: ', tab, filterOnSport);
if (filterOnSport) this.findTabParams.filterOnSport = filterOnSport;
this.tabs.select(tab);
});
但如果从未访问过上述选项卡,这在第一次时不起作用(请参阅https://github.com/ionic-team/ionic/issues/12592)
我在 Github issue 中看到有人建议模拟点击选项卡。
我正在尝试使用ViewChild这样做,但无法使其工作。
// View
<ion-tabs #tabs>
<ion-tab [root]="tab1Root" tabIcon="home"></ion-tab>
<ion-tab #findTab [root]="tab2Root" [rootParams]="findTabParams" tabIcon="search"></ion-tab>
<ion-tab [root]="tab3Root" tabIcon="chatbubbles" [tabBadge]="unread?1:null" [tabsHideOnSubPages]=true></ion-tab>
<!--<ion-tab [root]="tab3Root" tabIcon="chatbubbles" [tabBadge]="totalUnreadMessages?.$value" [tabsHideOnSubPages]=true></ion-tab>-->
</ion-tabs>
// Controller
@ViewChild('findTab') findTab: ElementRef;
...
ngAfterViewInit() {
console.log('TAB elem ', this.findTab);
// How click the tab ?
}
如何触发tab的点击功能?
【问题讨论】:
-
一个疯狂的猜测是:
this.findTab.nativeElement.click();另一种查找方法是使用浏览器中的 devtool,在 console.log 中破坏您的代码并在控制台中使用 findTab 元素,直到您寻找解决方案
标签: angular ionic2 ionic3 viewchild ionic-tabs