0

I have a AngularJS application that has a service module. I have simplyfied what i want to do in the code below. I want one service function to get a value from another function in the same service.

service.factory(....)
return {
    //test function want to get the value from "info" in test2.
    test: function () {
        var text = this.test2;
        return text;
    },
    test2: function () {
        var info = "Hello World";
        return info;
    }

When i call "test" function it returns the entire function:

function () {
        var info = "Hello World";
        return info;
    }

and not the "Hello World". Can someone explain why its not returning the value?

1 Answer 1

1

You need to call test2.

test: function () {
    var text = this.test2();  // <-- here
    return text;
},
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. Abit annoying to miss it :(

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.