In my Angular module, I have a service like this one :
myApp.service( 'myService', function(){
this.publicFunction1 = function(){
...
};
this.publicfunction2 = function(){
...
};
function privateFunction(){
...
}
});
At a point, I need to call one of the "public" function from a private one, like this :
function somePrivateFunc(){
this.publicFunction1();
...
}
But the element 'this' seems not to be visible inside the private function. How can I call publicFunction1() inside ?
Here is a workaround, but I'd like to understand plainly the situation. Can someone explain to me what happens here ? And is there a better way to do this ?
myApp.service( 'myService', function(){
var service = this;
this.publicFunction1 = function(){
...
};
this.publicfunction2 = function(){
...
};
function privateFunction(){
service.publicFunction1();
...
}
});