Search code examples
javascriptangularjsng-idle

Why is this function being ignored in Angular?


I'm using ngIdle and ngStorage in an effort to persist data that someone has entered to a page after they've been timed out, so that when they log back in the stuff they entered before signing out is still there.

My goal with the following code was to have a function that loads with the view that determines where to pull the values for appSettings (JSON that has all the form values from the page). So, I check to see if $localStorage.idleTimeout is true (a value that should only be stored if the user has been timed out).

My JavaScript looks like this:

var loadLocalStorage = function(){
        if($localStorage.idleTimeout){
            $scope.applicationSettings  = $localStorage.applicationSettings;
            $localStorage.idleTimeOut   = false;
        }
        else{
            $scope.applicationSettings = appSettings;
        }
    }

loadLocalStorage;

What's the problem? When going into the debugger it seems that the function doesn't even really try, it just skips over it. Even if $localStorage.idleTimeout isn't being set to true as it should be, I should still get the value for $scope.applicationSettings, but alas that is not the case.


Solution

  • It looks like you're simply not calling the function. To call a function in js, you need the parenthesis. Try :

    loadLocalStorage();