angularjs - How to sync ionic navigation bar and hardware button in android in a phonegap mobile app -


in phonegap app, there ionic navigation bar has button. if navigate app using navigation bar navigate each page, if use hardware button in point of time, navigation messed up. there fixes this.

<ion-view view-title="store locator" ng-controller="storelistctrl" >     <ion-nav-buttons side="right">          <button form="searchid" class="button button-icon icon ion-ios7-search" ng-click="search(searchform.searchtext)"></button>     </ion-nav-buttons>     <ion-content>         code here....     </ion-content>   </ion-view>  

this page in our app. button have overrided actions ioplatform.registerbackbuttonaction

$ionicplatform.registerbackbuttonaction(function (event) {        if($state.current.name==="app.home"){               var mypopup = $ionicpopup.show({                     title: 'exit application',                     scope: $scope,                     buttons: [                       { text: 'cancel',                          ontap: function(e) {                             $state.go("app.home");                         }                       },                       {                         text: 'yes',                         type: 'button-positive',                         ontap: function(e) {                             navigator.app.exitapp();                         }                       }                     ]                   });         }         else if($state.current.name==="app.couponlists"){             $state.go('app.home');         }         else if($state.current.name==="app.deallists"){             $state.go('app.home');         }         else if($state.current.name==="app.coupondetail"){             $state.go('app.couponlists');         }         else{           navigator.app.backhistory();         }       }, 100); 

go through docs first before implementing. ionic platform doc

options available

  1. onhardwarebackbutton(callback)
  2. offhardwarebackbutton(callback)
  3. registerbackbuttonaction(callback, priority, [actionid])
  4. on(type, callback)

make sure $ionicplatform.ready() called first.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -