fix(nav): use setRoot when root property changes

Closes #5668
This commit is contained in:
Adam Bradley
2016-03-06 23:33:44 -06:00
parent b814314b31
commit d77e8d963f
2 changed files with 48 additions and 8 deletions

View File

@ -106,11 +106,8 @@ import {ViewController} from './view-controller';
template: '<div #contents></div>' template: '<div #contents></div>'
}) })
export class Nav extends NavController { export class Nav extends NavController {
private _root: Type;
/** private _hasInit: boolean = false;
* @private
*/
@Input() root: Type;
constructor( constructor(
@Optional() hostNavCtrl: NavController, @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 * @private
*/ */
ngOnInit() { ngOnInit() {
if (this.root) { this._hasInit = true;
if (typeof this.root !== 'function') {
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.'; 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);
} }
} }

View File

@ -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);
}
}