diff --git a/ionic/components/nav/nav-controller.ts b/ionic/components/nav/nav-controller.ts index 05fba40983..f50e0298bb 100644 --- a/ionic/components/nav/nav-controller.ts +++ b/ionic/components/nav/nav-controller.ts @@ -699,24 +699,18 @@ export class NavController extends Ion { return done(); } - function loaded() { - // this ViewController instance has finished loading - try { - viewCtrl.loaded(); - } catch (e) { - console.error(e); - } - done(); - } - // get the pane the NavController wants to use // the pane is where all this content will be placed into this.loadPage(viewCtrl, null, () => { if (viewCtrl.onReady) { - viewCtrl.onReady(loaded); + viewCtrl.onReady(() => { + viewCtrl.loaded(); + done(); + }); } else { - loaded(); + viewCtrl.loaded(); + done(); } }); diff --git a/ionic/components/nav/test/basic/index.ts b/ionic/components/nav/test/basic/index.ts index 21e845d913..4470a4dd97 100644 --- a/ionic/components/nav/test/basic/index.ts +++ b/ionic/components/nav/test/basic/index.ts @@ -63,6 +63,12 @@ class FirstPage { } } + onPageLoaded() { + console.log('onPageLoaded'); + var meNoWorky = true; + meNoWorky(helloIsItMeYoureLookingFor); + } + setPages() { let items = [ PrimaryHeaderPage diff --git a/ionic/components/nav/view-controller.ts b/ionic/components/nav/view-controller.ts index 008d1579eb..f5f92c2c05 100644 --- a/ionic/components/nav/view-controller.ts +++ b/ionic/components/nav/view-controller.ts @@ -157,7 +157,7 @@ export class ViewController { loaded() { this._loaded = true; if (!this.shouldDestroy) { - this.instance.onPageLoaded && this.instance.onPageLoaded(); + ctrlFn(this, 'onPageLoaded'); } } @@ -166,7 +166,7 @@ export class ViewController { */ willEnter() { if (!this.shouldDestroy) { - this.instance.onPageWillEnter && this.instance.onPageWillEnter(); + ctrlFn(this, 'onPageWillEnter'); } } @@ -177,14 +177,14 @@ export class ViewController { didEnter() { let navbar = this.getNavbar(); navbar && navbar.didEnter(); - this.instance.onPageDidEnter && this.instance.onPageDidEnter(); + ctrlFn(this, 'onPageDidEnter'); } /** * The view has is about to leave and no longer be the active view. */ willLeave() { - this.instance.onPageWillLeave && this.instance.onPageWillLeave(); + ctrlFn(this, 'onPageWillLeave'); } /** @@ -192,21 +192,31 @@ export class ViewController { * will fire, whether it is cached or unloaded. */ didLeave() { - this.instance.onPageDidLeave && this.instance.onPageDidLeave(); + ctrlFn(this, 'onPageDidLeave'); } /** * The view is about to be destroyed and have its elements removed. */ willUnload() { - this.instance.onPageWillUnload && this.instance.onPageWillUnload(); + ctrlFn(this, 'onPageWillUnload'); } /** * The view has been destroyed and its elements have been removed. */ didUnload() { - this.instance.onPageDidUnload && this.instance.onPageDidUnload(); + ctrlFn(this, 'onPageDidUnload'); } } + +function ctrlFn(viewCtrl, fnName) { + if (viewCtrl.instance && viewCtrl.instance[fnName]) { + try { + viewCtrl.instance[fnName](); + } catch(e) { + console.error(fnName + ': ' + e.message); + } + } +} diff --git a/ionic/components/navbar/navbar.ts b/ionic/components/navbar/navbar.ts index d50eeda0e6..54276c333d 100644 --- a/ionic/components/navbar/navbar.ts +++ b/ionic/components/navbar/navbar.ts @@ -172,7 +172,11 @@ export class Navbar extends ToolbarBase { * @private */ didEnter() { - this.app.setTitle(this.getTitleText()); + try { + this.app.setTitle(this.getTitleText()); + } catch(e) { + console.error(e); + } } /**