Skip to content

Commit d77e8d9

Browse files
committed
fix(nav): use setRoot when root property changes
Closes #5668
1 parent b814314 commit d77e8d9

File tree

2 files changed

+48
-8
lines changed

2 files changed

+48
-8
lines changed

ionic/components/nav/nav.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,8 @@ import {ViewController} from './view-controller';
106106
template: '<div #contents></div>'
107107
})
108108
export class Nav extends NavController {
109-
110-
/**
111-
* @private
112-
*/
113-
@Input() root: Type;
109+
private _root: Type;
110+
private _hasInit: boolean = false;
114111

115112
constructor(
116113
@Optional() hostNavCtrl: NavController,
@@ -134,15 +131,32 @@ export class Nav extends NavController {
134131
}
135132
}
136133

134+
/**
135+
* @input {Page} The Page component to load as the root page within this nav.
136+
*/
137+
@Input()
138+
get root(): Type {
139+
return this._root;
140+
}
141+
set root(page: Type) {
142+
this._root = page;
143+
144+
if (this._hasInit) {
145+
this.setRoot(page);
146+
}
147+
}
148+
137149
/**
138150
* @private
139151
*/
140152
ngOnInit() {
141-
if (this.root) {
142-
if (typeof this.root !== 'function') {
153+
this._hasInit = true;
154+
155+
if (this._root) {
156+
if (typeof this._root !== 'function') {
143157
throw 'The [root] property in <ion-nav> must be given a reference to a component class from within the constructor.';
144158
}
145-
this.push(this.root);
159+
this.push(this._root);
146160
}
147161
}
148162

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import {App, Page} from 'ionic-angular';
2+
3+
4+
@Page({
5+
template: `
6+
<ion-content padding text-center>
7+
Page be loaded!
8+
</ion-content>
9+
`
10+
})
11+
class AsyncPage {}
12+
13+
14+
@App({
15+
template: `<ion-nav [root]="root"></ion-nav>`
16+
})
17+
class E2EApp {
18+
root;
19+
20+
constructor() {
21+
setTimeout(() => {
22+
this.root = AsyncPage;
23+
}, 1000);
24+
25+
}
26+
}

0 commit comments

Comments
 (0)