Jenkaa
Jenkaa

Reputation: 23

AngularJS Service function calling another function

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?

Upvotes: 0

Views: 1800

Answers (1)

JLRishe
JLRishe

Reputation: 101652

You need to call test2.

test: function () {
    var text = this.test2();  // <-- here
    return text;
},

Upvotes: 1

Related Questions