i created an app in ionic and while i was testing it i noticed that when i press the hardware back button the app completely terminates , i tried to override the event but nothing was happening , the strange about all of that is when i remove the ng-app=“starter” from my app the back button work completely fine and i can easily override it but certainly my ui becomes a mess , my question is how can i override the backbutton event ?
So you can register a new back button action with the follow code below.
$ionicPlatform.registerBackButtonAction(function (event) {
// Custom function
}, 100);
it is not working i tried it and nothing changes
maybe you can show us your code?
this is a link of a github repo that contain all of the code https://github.com/fadysamir/zabatni
This repository is empty.
Care to check out the GitHub Channel on YouTube while you wait?
sorry my internet speed is too low the code is being uploaded
it is now live
, you can check it
Well, put some custom code in it.
Example:
$ionicPlatform.registerBackButtonAction(function (event) {
// Custom function
event.preventDefault(); // Back button will DO NOTHING.
$state.go(url); //go to specific url
}, 100);
i put an alert and tried to make it navigate to another page and nothing was happening. @mhartington
i can only find this line in your index.html
<script type="text/javascript">document.addEventListener("backbutton", onBackKeyDown, false);
You have to create a controller and there you need to load $ionicPlatform and then use the suggested code by mhartington.
I am using this approach in all my apps and it is working.
check the test page i typed it there
Yeah and i told you… you need to create a angularjs controller for your module and put that code in there…
maybe you have to read some angularjs tutorials.
https://docs.angularjs.org/guide/controller
If you want to build ionic apps you have to learn angularjs.
i think may be this is my problem i do not know anything about angular js and it seems that all ionic functions are based on top of it