I have the following modal inside an ion view:
<ion-view id="doctors" cache-view="false" view-title="Directorio médico" ng-controller="DoctorsDirController as doctorsCtrl">
<ion-content>
<!-- stuff inside here -->
</ion-content>
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
When this modal is open disable android back button
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
<script id="result-details.html" type="text/ng-template">
<ion-modal-view id="result-details-modal">
<ion-content>
</ion-content>
</ion-modal-view>
</script>
</ion-view>
This is the state for parent view (doctors) inside config
in app.js:
.config(function ($stateProvider, $urlRouterProvider, $ionicConfigProvider) {
.state('doctors', {
url: '/doctors',
templateUrl: "templates/doctors.html"
})
So inside app.js run
I tried:
- disabling android back button for parent view
- but for all other views act as normal back button.
Code:
.run(function ($ionicPlatform, $state) {$ionicPlatform.ready(function () {
$ionicPlatform.registerBackButtonAction(function () {
//if we are in doctors do nothing
if ($state.current.url == "/doctors") {
//do nothing
//else if we are in dashboard exit app
} else if ($state.current.name == "dashboard") {
ionic.Platform.exitApp();
//else normal back-button functionality
} else {
navigator.app.backHistory();
}
}, 100);
})
The problem is that when modal is called inside "doctors" it seems to be a different state from the parent "doctors" and my android back button overriding doesn't work anymore.