I am currently working with an Angular factory that contains various functions. My goal is to use myService to retrieve data, and upon successful retrieval, call another function within the factory:
myApp.factory('myFactory', function($http) {
return {
myFunction: function() {
MyService.getData().then(
function(response) {
var something = response;
this.anotherFunction(something); //returns undefined
},
function (error) {
//something terrible happened
}
);
},
anotherFunction: function(something) {
console.log(something) //will not run
}
}
});
The issue arises because calling this.anotherFunction
results in 'undefined' being returned.