Skip to content

Commit 61a8625

Browse files
committed
fix(nav): register child nav when created from modal
1 parent 3977928 commit 61a8625

File tree

3 files changed

+30
-21
lines changed

3 files changed

+30
-21
lines changed

src/components/modal/test/basic/index.ts

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { ActionSheetController, App, Config, ionicBootstrap, ModalController, Na
55

66
@Injectable()
77
class SomeComponentProvider {
8-
constructor(private config: Config) {
8+
constructor(public config: Config) {
99
console.log('SomeComponentProvider constructor');
1010
}
1111

@@ -16,7 +16,7 @@ class SomeComponentProvider {
1616

1717
@Injectable()
1818
class SomeAppProvider {
19-
constructor(private config: Config) {
19+
constructor(public config: Config) {
2020
console.log('SomeAppProvider constructor');
2121
}
2222

@@ -32,7 +32,7 @@ class SomeAppProvider {
3232
class E2EPage {
3333
platforms: string[];
3434

35-
constructor(private nav: NavController, private modalCtrl: ModalController, config: Config, platform: Platform) {
35+
constructor(public navCtrl: NavController, public modalCtrl: ModalController, config: Config, platform: Platform) {
3636
console.log('platforms', platform.platforms());
3737
console.log('mode', config.get('mode'));
3838

@@ -117,11 +117,10 @@ class E2EPage {
117117
`
118118
})
119119
class NavigableModal {
120-
constructor(private nav: NavController) {
121-
}
120+
constructor(public navCtrl: NavController) {}
122121

123122
submit() {
124-
this.nav.push(NavigableModal2);
123+
this.navCtrl.push(NavigableModal2);
125124
}
126125
}
127126

@@ -139,7 +138,7 @@ class NavigableModal {
139138
`
140139
})
141140
class NavigableModal2 {
142-
constructor(private navController: NavController) {
141+
constructor(public navController: NavController) {
143142
}
144143

145144
submit() {
@@ -175,7 +174,7 @@ class NavigableModal2 {
175174
class ModalPassData {
176175
data: any;
177176

178-
constructor(params: NavParams, private viewCtrl: ViewController, someComponentProvider: SomeComponentProvider, someAppProvider: SomeAppProvider) {
177+
constructor(params: NavParams, public viewCtrl: ViewController, someComponentProvider: SomeComponentProvider, someAppProvider: SomeAppProvider) {
179178
this.data = {
180179
userId: params.get('userId'),
181180
name: someComponentProvider.getName()
@@ -245,7 +244,7 @@ class ModalPassData {
245244
})
246245
class ToolbarModal {
247246

248-
constructor(private viewCtrl: ViewController) {}
247+
constructor(public viewCtrl: ViewController) {}
249248

250249
dismiss() {
251250
this.viewCtrl.emit({
@@ -294,7 +293,7 @@ class ToolbarModal {
294293
class ModalWithInputs {
295294
data: any;
296295

297-
constructor(private viewCtrl: ViewController) {
296+
constructor(public viewCtrl: ViewController) {
298297
this.data = {
299298
title: 'Title',
300299
note: 'Note',
@@ -374,11 +373,10 @@ class ContactUs {
374373
`
375374
})
376375
class ModalFirstPage {
376+
items: any[] = [];
377377

378-
private items: any[];
379-
constructor(private nav: NavController, private app: App, private actionSheetCtrl: ActionSheetController) {
380-
this.items = [];
381-
for ( let i = 0; i < 50; i++ ) {
378+
constructor(public navCtrl: NavController, public app: App, public actionSheetCtrl: ActionSheetController) {
379+
for (let i = 0; i < 50; i++) {
382380
this.items.push({
383381
value: (i + 1)
384382
});
@@ -389,11 +387,11 @@ class ModalFirstPage {
389387
let page = ModalSecondPage;
390388
let params = { id: 8675309, myData: [1, 2, 3, 4] };
391389

392-
this.nav.push(page, params);
390+
this.navCtrl.push(page, params);
393391
}
394392

395393
dismiss() {
396-
this.app.getRootNav().pop();
394+
this.navCtrl.parent.pop();
397395
}
398396

399397
ionViewLoaded() {
@@ -465,15 +463,15 @@ class ModalFirstPage {
465463
</ion-header>
466464
<ion-content padding>
467465
<p>
468-
<button (click)="nav.pop()">Pop (Go back to 1st)</button>
466+
<button (click)="navCtrl.pop()">Pop (Go back to 1st)</button>
469467
</p>
470468
<f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f>
471469
<f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f>
472470
</ion-content>
473471
`
474472
})
475473
class ModalSecondPage {
476-
constructor(private nav: NavController, params: NavParams) {
474+
constructor(public navCtrl: NavController, params: NavParams) {
477475
console.log('Second page params:', params);
478476
}
479477

src/components/nav/nav.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,15 @@ export class Nav extends NavControllerBase implements AfterViewInit {
8181
// this Nav has a parent Nav
8282
parent.registerChildNav(this);
8383

84-
} else if (app) {
84+
} else if (viewCtrl && viewCtrl.getNav()) {
85+
// this Nav was opened from a modal
86+
this.parent = viewCtrl.getNav();
87+
this.parent.registerChildNav(this);
88+
89+
} else if (app && !app.getRootNav()) {
90+
// a root nav has not been registered yet with the app
8591
// this is the root navcontroller for the entire app
86-
this._app.setRootNav(this);
92+
app.setRootNav(this);
8793
}
8894
}
8995

src/components/tabs/tabs.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,11 @@ export class Tabs extends Ion {
274274
// this Tabs has a parent Nav
275275
this.parent.registerChildNav(this);
276276

277+
} else if (viewCtrl && viewCtrl.getNav()) {
278+
// this Nav was opened from a modal
279+
this.parent = <any>viewCtrl.getNav();
280+
this.parent.registerChildNav(this);
281+
277282
} else if (this._app) {
278283
// this is the root navcontroller for the entire app
279284
this._app.setRootNav(this);
@@ -375,7 +380,7 @@ export class Tabs extends Ion {
375380
* @private
376381
*/
377382
private _setConfig(attrKey: string, fallback: any) {
378-
var val = this[attrKey];
383+
var val = (<any>this)[attrKey];
379384
if (isBlank(val)) {
380385
val = this._config.get(attrKey, fallback);
381386
}

0 commit comments

Comments
 (0)