From d77e8d963f53a4531ec53be720660cd3158cd7bf Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Sun, 6 Mar 2016 23:33:44 -0600 Subject: [PATCH] fix(nav): use setRoot when root property changes Closes #5668 --- ionic/components/nav/nav.ts | 30 ++++++++++++++----- ionic/components/nav/test/init-async/index.ts | 26 ++++++++++++++++ 2 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 ionic/components/nav/test/init-async/index.ts diff --git a/ionic/components/nav/nav.ts b/ionic/components/nav/nav.ts index 1a11bf757b..c9d948cf1d 100644 --- a/ionic/components/nav/nav.ts +++ b/ionic/components/nav/nav.ts @@ -106,11 +106,8 @@ import {ViewController} from './view-controller'; template: '
' }) export class Nav extends NavController { - - /** - * @private - */ - @Input() root: Type; + private _root: Type; + private _hasInit: boolean = false; constructor( @Optional() hostNavCtrl: NavController, @@ -134,15 +131,32 @@ export class Nav extends NavController { } } + /** + * @input {Page} The Page component to load as the root page within this nav. + */ + @Input() + get root(): Type { + return this._root; + } + set root(page: Type) { + this._root = page; + + if (this._hasInit) { + this.setRoot(page); + } + } + /** * @private */ ngOnInit() { - if (this.root) { - if (typeof this.root !== 'function') { + this._hasInit = true; + + if (this._root) { + if (typeof this._root !== 'function') { throw 'The [root] property in must be given a reference to a component class from within the constructor.'; } - this.push(this.root); + this.push(this._root); } } diff --git a/ionic/components/nav/test/init-async/index.ts b/ionic/components/nav/test/init-async/index.ts new file mode 100644 index 0000000000..c49553ff05 --- /dev/null +++ b/ionic/components/nav/test/init-async/index.ts @@ -0,0 +1,26 @@ +import {App, Page} from 'ionic-angular'; + + +@Page({ + template: ` + + Page be loaded! + + ` +}) +class AsyncPage {} + + +@App({ + template: `` +}) +class E2EApp { + root; + + constructor() { + setTimeout(() => { + this.root = AsyncPage; + }, 1000); + + } +}