feat(angular): tabs.select()

fixes #16753
This commit is contained in:
Manu Mtz.-Almeida
2018-12-16 17:44:58 +01:00
committed by Manu MA
parent 60ef98d1a7
commit 56dd8ae342
3 changed files with 9 additions and 6 deletions

View File

@ -197,6 +197,10 @@ export class IonRouterOutlet implements OnDestroy, OnInit {
const active = this.stackCtrl.getLastUrl(stackId); const active = this.stackCtrl.getLastUrl(stackId);
return active ? active.url : undefined; return active ? active.url : undefined;
} }
getActiveStackId() {
return this.stackCtrl.getActiveStackId();
}
} }
function emitEvent(el: HTMLElement, view: RouteView) { function emitEvent(el: HTMLElement, view: RouteView) {

View File

@ -1,5 +1,4 @@
import { Component, ContentChild, HostListener, ViewChild } from '@angular/core'; import { Component, ContentChild, HostListener, ViewChild } from '@angular/core';
import { TabButtonClickDetail } from '@ionic/core';
import { NavController } from '../../providers'; import { NavController } from '../../providers';
import { IonTabBar } from '../proxies'; import { IonTabBar } from '../proxies';
@ -57,14 +56,14 @@ export class IonTabs {
} }
} }
@HostListener('ionTabButtonClick', ['$event.detail']) @HostListener('ionTabButtonClick', ['$event.detail.tab'])
onTabButtonClick(detail: TabButtonClickDetail) { select(tab: string) {
const { tab, selected } = detail; const selected = this.outlet.getActiveStackId() === tab;
const href = `${this.outlet.tabsPrefix}/${tab}`; const href = `${this.outlet.tabsPrefix}/${tab}`;
const url = selected const url = selected
? href ? href
: this.outlet.getLastUrl(tab) || href; : this.outlet.getLastUrl(tab) || href;
this.navCtrl.navigateBack(url, true); return this.navCtrl.navigateBack(url, true);
} }
} }

View File

@ -90,7 +90,7 @@ export class StackController {
return views.length > 0 ? views[views.length - 1] : undefined; return views.length > 0 ? views[views.length - 1] : undefined;
} }
private getActiveStackId(): string | undefined { getActiveStackId(): string | undefined {
return this.activeView ? this.activeView.stackId : undefined; return this.activeView ? this.activeView.stackId : undefined;
} }