2

i'm building a login service to my website and i need help on this: i want to check if login was done and if is true do the function at 'yes' variable. Else, do the 'no' variable. Like this:

app.service('login', function($cookies) {
// Cookie status = login status
var cookie_status = $cookies.get('login_status');

// Cookie token = login token
var cookie_token = $cookies.get('login_token');

this.status = function(){
    return cookie_status
};
this.iflogin = function(yes, no){
    if(cookie_status=='yes'){
        return yes;
    } else {
        no;
    }
}; });

But, therefore, when i call this function the function at 'yes' or 'no' variable aren't done. That is my call:

login.iflogin(function yes(){
    $scope.login = "Conta";
}, function no(){
    $scope.login = "Login";
});

Where is the problem!?

Thank you and sincerely, Lucas.

1 Answer 1

1

You don't need to return inside the iflogin function, you simply need to call either of the functions like this:

this.iflogin = function(yes, no){
    if(cookie_status=='yes'){
        yes();
    } else {
        no();
    }
};
Sign up to request clarification or add additional context in comments.

1 Comment

You are right. I tried this way, without return but i forgot the parentheses. Thank you, ;)

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.