I have created an AngularJS factory in which I'm returning an object which has some functions as properties. My purpose is to call some function in another function from that returning using the this keyword but its giving an error. I tried to console.log the this keyword and I found out that, that this variable holds the scope of calling controller in which the factory is being injected. How can I tackle this kind of situation. this keyword should return the current returning object!
app.module('admin').factory('login', [function() {
return {
someFunc: function() {
return 'abc'
},
anotherFunc : function(){
var msg = this.someFunc();
return 'Msg is '+ msg;
},
yetAnotherFunc : function(){
var msg = this.someFunc();
return 'Msg is '+ msg;
}
}
}]).controller(['$scope', 'login', function($scope, login){
login.someFunc(); // Works Fine
login.anotherFunc(); // Error : this.someFunc is not a function
}])