Reputation: 21
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 :)
Upvotes: 0
Views: 108