diff --git a/ionic/components/nav/nav-base.js b/ionic/components/nav/nav-base.js index f2dcc3be7d..6d45229b68 100644 --- a/ionic/components/nav/nav-base.js +++ b/ionic/components/nav/nav-base.js @@ -190,24 +190,6 @@ export class NavBase { return promise; } - select(enteringItem, opts = {}) { - if (!enteringItem || !enteringItem.instance || this.isTransitioning()) { - return; - } - - enteringItem.instance.loadInitial(); - - opts.animation = 'none'; - - let leavingItem = this.getActive() || new NavItem(); - leavingItem.shouldDestroy = false; - leavingItem.shouldCache = true; - leavingItem.willCache(); - - this.transition(enteringItem, leavingItem, opts, () => { - }); - } - transition(enteringItem, leavingItem, opts, callback) { if (!enteringItem || enteringItem === leavingItem) { return callback(); diff --git a/ionic/components/tabs/tab-button.js b/ionic/components/tabs/tab-button.js index 9a7009d2e7..884ab81c8e 100644 --- a/ionic/components/tabs/tab-button.js +++ b/ionic/components/tabs/tab-button.js @@ -31,6 +31,6 @@ export class TabButton { onClick(ev) { ev.stopPropagation(); ev.preventDefault(); - this.tabs.selectTab(this.tab); + this.tabs.select(this.tab); } } diff --git a/ionic/components/tabs/tab.js b/ionic/components/tabs/tab.js index 33bb1084e2..0ddcbb21ad 100644 --- a/ionic/components/tabs/tab.js +++ b/ionic/components/tabs/tab.js @@ -79,10 +79,14 @@ export class Tab extends NavBase { } } - loadInitial() { - if (this.initial && !this._loaded) { - this.push(this.initial); + loadInitial(callback) { + if (!this._loaded && this.initial) { + this.push(this.initial).then(() => { + callback && callback(); + }); this._loaded = true; + } else { + callback && callback(); } } diff --git a/ionic/components/tabs/tabs.js b/ionic/components/tabs/tabs.js index 1a1f8f839a..6203048ac3 100644 --- a/ionic/components/tabs/tabs.js +++ b/ionic/components/tabs/tabs.js @@ -58,18 +58,36 @@ export class Tabs extends NavBase { this.add(tabItem); if (this.length() === 1) { - this.selectTab(0); + this.select(0); } } - selectTab(tab) { - let item = null; + select(tab) { + let enteringItem = null; if (typeof tab === 'number') { - item = this.getByIndex(tab); + enteringItem = this.getByIndex(tab); } else { - item = this.getByInstance(tab) + enteringItem = this.getByInstance(tab) } - this.select(item); + + if (!enteringItem || !enteringItem.instance || this.isTransitioning()) { + return; + } + + enteringItem.instance.loadInitial(() => { + let opts = { + animation: 'none' + }; + + let leavingItem = this.getActive() || new NavItem(); + leavingItem.shouldDestroy = false; + leavingItem.shouldCache = true; + leavingItem.willCache(); + + this.transition(enteringItem, leavingItem, opts, () => { + console.log('tab selected') + }); + }); } get tabs() {