I think it is best practice to use a service that returns information of a http call as a promise and these information should be added to the scope in the controller. Like:
awesomeService.getAllInformation().then(data){
$scope.data = data;
}
Question: If i want to filter the returned information of the http call, do I do this in the controller? or in a separate method in the service? Example in Controller:
awesomeSvc.getAllInformation().then(data){
angular.forEach(data,function(dataItem, dataIndex){
if(dataItem === 'foo'){
$data = dataItem
}
}
}
Or do i create a second service that is responsible for manipulation or filtering of the information received by the http call. Like this file structure:
File1: service for all http calls File2: service for manipulation of the calls File3: controller
So that the awesomeService call would be made in the second service:
function dataManipulationInSecondService(){
var data = "";
awesomeService.getAllInformation().then(data){
angular.forEach(data,function(dataItem, dataIndex){
if(dataItem === 'foo'){
data = dataItem
}
}
}
return data;
}
And then in the controller:
secondService.dataManipulationInSecondService().then(data){
$scope.data = data;
}
I hope my question is not too confusing and somebody can tell me the best practice ;)
Thanks for your help