Skip to content

Commit

Permalink
feat(backbutton): add hardware back button
Browse files Browse the repository at this point in the history
Closes #5071
  • Loading branch information
adamdbradley committed Apr 10, 2016
1 parent 156fdc3 commit 68278b0
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions ionic/components/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import {Title} from 'angular2/platform/browser';

import {Config} from '../../config/config';
import {ClickBlock} from '../../util/click-block';
import {Nav} from '../nav/nav';
import {Tabs} from '../tabs/tabs';
import {Platform} from '../../platform/platform';


/**
Expand All @@ -23,8 +22,20 @@ export class IonicApp {

constructor(
private _config: Config,
private _clickBlock: ClickBlock
) {}
private _clickBlock: ClickBlock,
platform: Platform
) {
platform.backButton.subscribe(() => {
let activeNav = this.getActiveNav();
if (activeNav) {
if (activeNav.length() === 1) {
platform.exitApp();
} else {
activeNav.pop();
}
}
});
}

/**
* Sets the document title.
Expand Down Expand Up @@ -102,7 +113,7 @@ export class IonicApp {
/**
* @private
*/
getActiveNav(): Nav | Tabs {
getActiveNav(): any {
var nav = this._rootNav || null;
var activeChildNav;

Expand Down

0 comments on commit 68278b0

Please sign in to comment.