feat(angular): expose getSelected() (#17079)

fixes #17068
This commit is contained in:
Manu MA
2019-01-14 18:03:44 +01:00
committed by GitHub
parent 8789748334
commit 3c801dbe11
8 changed files with 52 additions and 39 deletions

View File

@ -176,19 +176,19 @@ Using tabs with Angular's router is fairly straight forward. Here you only need
## Methods
### `getSelected() => Promise<HTMLIonTabElement | undefined>`
### `getSelected() => Promise<string | undefined>`
Get the currently selected tab
#### Returns
Type: `Promise<HTMLIonTabElement | undefined>`
Type: `Promise<string | undefined>`
### `getTab(tab: string | HTMLIonTabElement) => Promise<HTMLIonTabElement | undefined>`
Get the tab at the given index
Get the tab element given the tab name
#### Parameters

View File

@ -99,6 +99,29 @@ export class Tabs implements NavOutlet {
return true;
}
/**
* Get the tab element given the tab name
*/
@Method()
async getTab(tab: string | HTMLIonTabElement): Promise<HTMLIonTabElement | undefined> {
const tabEl = (typeof tab === 'string')
? this.tabs.find(t => t.tab === tab)
: tab;
if (!tabEl) {
console.error(`tab with id: "${tabEl}" does not exist`);
}
return tabEl;
}
/**
* Get the currently selected tab
*/
@Method()
getSelected(): Promise<string | undefined> {
return Promise.resolve(this.selectedTab ? this.selectedTab.tab : undefined);
}
/** @internal */
@Method()
async setRouteId(id: string): Promise<RouteWrite> {
@ -122,27 +145,6 @@ export class Tabs implements NavOutlet {
return tabId !== undefined ? { id: tabId, element: this.selectedTab } : undefined;
}
/** Get the tab at the given index */
@Method()
async getTab(tab: string | HTMLIonTabElement): Promise<HTMLIonTabElement | undefined> {
const tabEl = (typeof tab === 'string')
? this.tabs.find(t => t.tab === tab)
: tab;
if (!tabEl) {
console.error(`tab with id: "${tabEl}" does not exist`);
}
return tabEl;
}
/**
* Get the currently selected tab
*/
@Method()
getSelected(): Promise<HTMLIonTabElement | undefined> {
return Promise.resolve(this.selectedTab);
}
private async initSelect(): Promise<void> {
if (this.useRouter) {
return;