Skip to content

Commit 68278b0

Browse files
committed
feat(backbutton): add hardware back button
Closes #5071
1 parent 156fdc3 commit 68278b0

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

ionic/components/app/app.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import {Title} from 'angular2/platform/browser';
33

44
import {Config} from '../../config/config';
55
import {ClickBlock} from '../../util/click-block';
6-
import {Nav} from '../nav/nav';
7-
import {Tabs} from '../tabs/tabs';
6+
import {Platform} from '../../platform/platform';
87

98

109
/**
@@ -23,8 +22,20 @@ export class IonicApp {
2322

2423
constructor(
2524
private _config: Config,
26-
private _clickBlock: ClickBlock
27-
) {}
25+
private _clickBlock: ClickBlock,
26+
platform: Platform
27+
) {
28+
platform.backButton.subscribe(() => {
29+
let activeNav = this.getActiveNav();
30+
if (activeNav) {
31+
if (activeNav.length() === 1) {
32+
platform.exitApp();
33+
} else {
34+
activeNav.pop();
35+
}
36+
}
37+
});
38+
}
2839

2940
/**
3041
* Sets the document title.
@@ -102,7 +113,7 @@ export class IonicApp {
102113
/**
103114
* @private
104115
*/
105-
getActiveNav(): Nav | Tabs {
116+
getActiveNav(): any {
106117
var nav = this._rootNav || null;
107118
var activeChildNav;
108119

0 commit comments

Comments
 (0)