0

I'm new to Ionic and AngularJS and can't figure out why this does'nt work, i just want to check when on "Home" tab if the user has already entered its card number, if not, redirect him to the appropriate page Here's my controller:

.controller('HomeCtrl', function($scope, $state) {
    if (localStorage.getItem("cardId") == "")
      {
        console.log("redirecting to login");
        $state.go('tab.dash');
      }
})

$state.go seems to do nothing but the console log is properly displayed. I tried with $timeout and $location.path without success.

Here are my routes :

  $stateProvider

    .state('tab', {
    url: '/tab',
    abstract: true,
    templateUrl: 'templates/tabs.html'
  })

    .state('tab.home', {
    url: '/home',
    views: {
      'tab-home': {
        templateUrl: 'templates/tab-home.html',
        controller: 'HomeCtrl',
      }
    }
  })

  .state('tab.dash', {
    url: '/dash',
    views: {
      'tab-dash': {
        templateUrl: 'templates/tab-dash.html',
        controller: 'DashCtrl',
      }
    }
  })

  .state('tab.map', {
      url: '/map',
      views: {
        'tab-map': {
          templateUrl: 'templates/tab-map.html',
          controller: 'MapCtrl'
        }
      }
    })

  .state('tab.account', {
    url: '/account',
    views: {
      'tab-account': {
        templateUrl: 'templates/tab-account.html',
        controller: 'AccountCtrl'
      }
    }
  });

      $urlRouterProvider.otherwise('/tab/home');
});

What I am doing wrong ? I just want to change the state...

Thanks :)

Infitek
  • 21
  • 2
  • 2
    show us your routes definitions. Sure that state exists with that name? – yBrodsky May 29 '17 at 14:46
  • yes i'm pretty sure since i get an error when I try with a non-existing state – Infitek May 29 '17 at 14:56
  • sure DashCtrl doesn't have some kind of error and the html (from the parent and the child) exist? – yBrodsky May 29 '17 at 15:03
  • I don't think there could be a problem in DashCtrl as it's just this piece of code : .controller('DashCtrl', function($scope) { console.log("in dash !"); }) And yes the tab-dash.html exist, but what do you mean by "from the parent and the child" ? Also, thank you for your time – Infitek May 29 '17 at 15:12
  • I meant tabs.html, which is the parent – yBrodsky May 29 '17 at 15:13
  • Ok, i'm stupid, I forgot to add tab-dash in tabs.html... Solved ! Thank you very much – Infitek May 29 '17 at 15:17

0 Answers0