Lamin L Janneh Lamin L Janneh - 3 months ago 9x
Javascript Question

how to check for a condition on the entire AngularJS app

I want to check if the User is still Active if not
I want to redirect it to the Login page

I am having this check in a controller which is not
a good Idea. Can someone help me please.

this is the Controller

['localStorageService','$scope', '$location', '$window', function
(localStorageService, $scope, $location, $window) {

var isValid = localStorageService.get("userID");
// I want this condition be check on every view in this application
if (isValid ==null)
$window.location = "/AngularView/html/Master.html#/Login";



You can simply add below code in routes

$urlRouterProvider.otherwise(function(){ var isValid = localStorageService.get("userID"); if (isValid ==null){ return '/Login'; }else{ // Your home page state url } });