Skip to content

Commit

Permalink
fix(nav): use setRoot when root property changes
Browse files Browse the repository at this point in the history
Closes #5668
  • Loading branch information
adamdbradley committed Mar 7, 2016
1 parent b814314 commit d77e8d9
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 8 deletions.
30 changes: 22 additions & 8 deletions ionic/components/nav/nav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,8 @@ import {ViewController} from './view-controller';
template: '<div #contents></div>'
})
export class Nav extends NavController {

/**
* @private
*/
@Input() root: Type;
private _root: Type;
private _hasInit: boolean = false;

constructor(
@Optional() hostNavCtrl: NavController,
Expand All @@ -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 <ion-nav> must be given a reference to a component class from within the constructor.';
}
this.push(this.root);
this.push(this._root);
}
}

Expand Down
26 changes: 26 additions & 0 deletions ionic/components/nav/test/init-async/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {App, Page} from 'ionic-angular';


@Page({
template: `
<ion-content padding text-center>
Page be loaded!
</ion-content>
`
})
class AsyncPage {}


@App({
template: `<ion-nav [root]="root"></ion-nav>`
})
class E2EApp {
root;

constructor() {
setTimeout(() => {
this.root = AsyncPage;
}, 1000);

}
}

0 comments on commit d77e8d9

Please sign in to comment.