Programmatically set transitions and direction between states

Hi everyone,

I have discovered Ionic only recently, as well as Angular and i have to say that I am pleased with what I have seen. So far I found ways to do what I wanted to do, except for something with the navigation. I have upgraded to Ionic b14 yesterday but I don’t still it helped.

Manual back button

I have found that using $state.go() was the way to go to programmatically nagivate between pages. Only that it does not seem to support whether or not the animation should represent back or forward action. Use case: I have a home page that displays 7 days, if you click on 1 day you end up on a screen with a slide-box. That slide-box allows you to go any day you want, but that when my users click on the back button they get to the week corresponding to the day they were on, so not necessarily the same screen as the previous one. The problem is that the direction of the animation ends up being forward, which is really strange.

I tried using the directives navDirection and navTransition but I think that the fact that my custom back button is in the navbar creates some conflicts. I also tried to pass some parameters to the $state, and many other things that I cannot remember. Am I missing something?

Thanks in advance!


This is really a blocker for me as my navigation is not standard. I guess a hack could be to force a click on a hidden button that defines navDirection/navTransition but I don’t really want to do that.

I am also encountering this problem. Anyone?

I was having issues getting navDirection to work. Changing the priority of the navDirection directive from 1000 to -10 seems to help as a workaround.

You can also try something like this, which is working for me. I define a field called stateUpward in each of my states defined by $stateProvider.state.

.run(function($rootScope, $ionicViewSwitcher) {
  $rootScope.$on('$stateChangeStart', function(evt, toState, toParams, fromState, fromParams) {
    var direction = null;
    if (fromState.stateUpward === direction = 'back';
    if (toState.stateUpward === direction = 'forward';
    if (direction) $ionicViewSwitcher.nextDirection(direction);
1 Like

Why do I get an error unknown provider when I declared $ionicViewSwitcher as dependency in my controller?