0

The problem is simply to reload the authentication token at regular interval. I am using $interval service for that. the code is as follows

function refresh_session() {
    console.log("testing");
}

module.exports = function ($scope,$rootScope,$localStorage,$location,$interval,$http) {

    $interval(refresh_session,5000);

This works just fine, but i need to access variables inside $scope and $localStorage to update the token. I have tried both passing a function defined inside $scope to $interval service as well as passing parameters to external function. Both of them are not working. What is the correct way i can go about that using the angular method ?

1 Answer 1

1

Are you able to place the refresh_session function inside your exported function? That would allow it to access that functions arguments. Like this:

module.exports = function ($scope,$rootScope,$localStorage,$location,$interval,$http) {

    $interval(refresh_session,5000);

    function refresh_session() {
        console.log("testing", $scope, $localStorage);
    }
    ...
};

Alternatively, you can have a function that creates the refresh_session function:

function refreshSessionCreator($scope, $localStorage){
    return function(){
        console.log("testing", $scope, $localStorage);
    };
}

module.exports = function ($scope,$rootScope,$localStorage,$location,$interval,$http) {

    $interval(refreshSessionCreator($scope, $localStorage),5000);
    ...
};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.