Suraz Khanal Suraz Khanal - 1 year ago 74
AngularJS Question

How to call function in angularjs factory

this is my factory and i want to call getData in saveData.Here is my code

.factory('dataSyncOperation', function($q,$http){
return {
var q = $q.defer();
var config = {
headers : {
'Content-Type': 'application/json'
return q.promise;





How can i use the promise returned by getData into saveData.

Answer Source

You can always do, something like this -

  this.getData().then(function(response){ // you can handle getData promise here
     // on success 
  }, function(reject){
     // on failure

inside your saveData method, let me know if this is what something you are looking for.

Working Example -

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download