0

i want all the data processing to be done in the service/factory and i just want to get the data back from it,

Currently what i am doing is like this:

.controller('homeCtrl', function($scope, companyFactory){
   companyFactory.getNames().then(function(result){
     //got the data
     //do some processing and checks
  })//then
})//controller

in my factory i have the following:

.factory('companyFactory', function($http) {
  var myObject ={
  getNames:function(){
       var dataReq = {
             method: 'POST',
             url: 'somesite.com'
       }
       return $http(dataReq);
    }//getnames
  } //my object
 return myObject;
  })

This works fine but i want to do something like this.

.factory('companyFactory', function($http) {
  var myObject ={
  getNames:function(){
       var dataReq = {
             method: 'POST',
             url: 'somesite.com'
       }
       $http(dataReq).then(function(){
          //got the data
          //do some processing and checks
          //return the processed data
        });
    }//getnames
  } //my object
 return myObject;
  })

How can this be done?

krv
  • 2,830
  • 7
  • 40
  • 79
  • 1
    Check out $q. You can return your own $q promise, do your processing and then call $q.resolve(myData). – lintmouse Aug 12 '15 at 12:24
  • got it from here http://stackoverflow.com/questions/27238928/angularjs-http-call-in-a-service-return-resolved-data-not-promises thanks – krv Aug 12 '15 at 12:27

0 Answers0