Basically what I'm trying to do is change the state depending on user authentication status.
When I do $state.go(); without $rootScope, I can redirect to the page without the error but when I do with
$rootScope.$on('$stateChangeStart', function (event) {
$state.go();
event.preventDefault()
})
Below Is the Controller Code:
DiaryDashboard.controller('AppController',
['$scope', '$rootScope', '$localStorage', '$http', '$state'
, function ($scope, $rootScope, $localStorage, $http, $state) {
$rootScope.$on('$stateChangeStart', function (event, toState) {
if ($localStorage.userdetails &&
$localStorage.userdetails.isAuthenticated == true) {
//Check for Authentication state
//If not redirect to the state in the else clause
//Populate the $rootScope with user details
$rootScope.userdetails = $localStorage.userdetails;
//Switch to the parent state
$state.go();
event.preventDefault();
} else {
//If User not authenticated
//GO to the Authentication State
$state.go('auth');
event.preventDefault();
}
})
}]);
$state.go()it calls$stateChangeStart& this cycle going on$state.go();is required when user is authenticated..why you want to get back to parent state event if he is authenticated