In the Ionic project, the HTML tag to achieve an animated switch page is simple, as long as the label to add nav-direction= "back" or nav-direction= "forward" can be achieved. But with $state.go () How to achieve animation effect. It is also very simple, just add $ionicViewSwitcher after $state.go (). Nextdirection ("Back") or $ionicViewSwitcher. Nextdirection ("Forwoard") You can achieve the same effect as add nav-direction, remember to inject ionicviewswitcher service. What if you want to implement this effect on the Android phone's return key?
The first thing to do is register the return key time in the. Run method, and then add $ionicviewswitcher.nextdirection ("Back") after $ionichistory.goback () or Ionicviewswitcher.nextdirection ("Forwoard")
$ionicPlatform. Registerbackbuttonaction (function (e) {
E.preventdefault ();
function Showconfirm () {
var confirmpopup = $ionicPopup. Confirm ({
Title: ' <strong> exit Application?</strong> ',
Template: ' Are you sure you want to quit the app? ',
Oktext: ' Exit ',
Canceltext: ' Cancel '
});
Confirmpopup.then (function (res) {
if (res) {
Ionic. Platform.exitapp ();
} else {
Don ' t close
}
});
}
Is there a page to go?
if ($location. path () = = '/tab/dash ') {
Showconfirm ();
} else if ($ionicHistory. Backview ()) {
Go Back on history
$ionicHistory. GoBack ();
$ionicViewSwitcher. Nextdirection ("Back");
} else {
The last Page:show confirmation popup
Showconfirm ();
}
return false;
}, 101);