I have a data service in my application that is responsible for receiving information for my controllers. This information may come from local storage, a window, or an ajax request. The problem I ran into is the $qpromise answers are not like the answers $http.
this.getContactDetails = function(data) {
if(typeof $window.preloadData.contact !== 'undefined') {
var contactDetails = JSON.parse(JSON.stringify($window.preloadData.contact));
delete $window.preloadData.contact;
var deferred = $q.defer();
deferred.resolve(contactDetails);
return deferred.promise;
}
var request = requests.contactDetails.get;
return $http(request);
};
The service $qdoes a nice job here, but it decides as the object that he defined. I would not expect it to return an answer. I know I $httpBackendcan accomplish this.
$httpBackend.whenGET(request).respond(contactDetails);
MockE2E, , . , , , . , , , $httpBackend, , $http. $httpBackend , url, body headers, $http .
- $http- .
var contactDetails = JSON.parse(JSON.stringify({
data: $window.preloadData.contact
}));
. / ?