Is there a way to pass the response value to the parent object, specifically the invoker of an http service call in AngularJS? I have a BaseModel that performs the GET request as shown below. The goal is for the basemodel object instance to hold the response values. I am trying to achieve this without using broadcast and on methods.
To invoke the object:
model = new BaseModel(); model.get();
Definition:
BaseModel.$service = ['$http', '$q', function ($http, $q) { return function () { return new BaseModel($http, $q); };
}];
The actual BaseModel:
function BaseModel($http, $q) { var q = $q.defer(); this.http = $http; this.response = null; // this is to hold the response value this.get = function () { var request = this.http({ url: 'http://blahblah.com?a=1&b=2', method: "GET", }); request.success(function (response) { q.resolve(response); }); q.promise.then( function(response){ console.log(response, ' got response'); //the idea is to have this.response = response return response; } ); return q.promise; };