I am making a call from a controller in AngularJS, which passes data to a service to get a response in which I need to then check with a condition.
Controller
patents.forEach(function(item){ //patents is resolved in a router file which returns a number of items from a request item.renewalProgress = patentsService.phaseProgress(item); }) Service
factory.phaseProgress = function(item) { var progress = function(item) factory.fetchCostAnalysis(phase.id) .then( function(response){ var progress; switch(response.currentcostBand) { case 'Green': progress = 0; break; case 'Amber': progress = 20; break; case 'Red': progress = 40; break; case 'Blue': progress = 60; break; case ' progress = 80; } return progress }, function(errResponse){ console.log('no') } ) return progress; } The value is coming back as undefined.
Question
How do I return a value to the controller from the service? If anyone can suggest a better approach even?