Could someone assist me in creating multiple functions within an AngularJS Factory? I am looking to access the returned value from one function and process it in another function. I attempted the code below without success.
In the following function, I want to retrieve the value in the modifyProduct function that we receive from getProduct(response.data)
I have looked at the questions below but did not gain much insight:
AngularJS : From a factory, how can I call another function
Calling a function in another function with AngularJS factory
app.factory('ProductsService', function($http) {
function getProduct() {
return $http.get('finalmsodetails.json').then(function(response) {
console.log(response.data);
return response.data;
});
}
function modifyProduct() {
this.getProduct().then(function(value) {
console.log(value);
});
}
return {
getProduct: getProduct,
modifyProduct: modifyProduct
};
});