BlondePainter BlondePainter - 20 days ago 6
AngularJS Question

Angular page redirection if returned value is false

in my controller i have this code that simply get the

logged_status
.



app.controller('dashboardCtrl', function($scope, $stateParams, $http) {
$scope.displaySN = '';
$scope.studentNumber = sessionStorage.getItem('student_number');
$scope.get_logged_status = sessionStorage.getItem('logged_status');
console.log("Dashboard Page Logged Status: " + $scope.get_logged_status);

if(!$scope.get_logged_status)
{
console.log('should redirect because false');
}else{
console.log('should stay because true');
}

})





it is getting the correct value but when i test the value of it and log a certain statement, im getting an unexpected result. in the image below, instead of getting
should redirect because false
because
$scope.get_logged_status
is valued
false
, im getting the opposite result. Help Please. Am i coding it wrong?

Please see image here

enter image description here

Answer

try this :

 if($scope.get_logged_status=="false")

maybe the item logged_status in the sessionStorage is considered as string not a boolean, so it returns always true