I was developing my application using a json file on my local computer and am now ready to start testing on the server but I am obtaining incomplete responses from my $http requests for some reason.
I have the following service that requests all of the data using 4 promises:
angular
.module('myApp')
.service('ProductService',
['$http','$q', '$filter', '$resource' ,ProductService]);
function ProductService($http,$q,$filter) {
var self = this;
//Callable members of this service---------------
self.getProducts = getProducts;
self.getVendors = getVendors;
self.getCategories = getCategories;
self.getAllData = getAllData;
self.getInventory = getInventory;
//---------------//---------------//---------------
function getProducts() {
var d = $q.defer();
$http({method : 'GET', url : GET_PRODUCTS_URL})
.then(function(response) {
d.resolve(response.data);
},function (error) {
d.reject(error);
});
return d.promise;
}
function getVendors() {
var d = $q.defer();
$http({method : 'GET', url : GET_VENDORS_URL})
.then(function(response) {
d.resolve(response.data);
},function (error) {
d.reject(error);
});
return d.promise;
}
function getCategories() {
var d = $q.defer();
$http({method : 'GET', url : GET_CATEGORIES_URL})
.then(function(response) {
d.resolve(response.data);
},function (error) {
d.reject(error);
});
return d.promise;
}
function getInventory() {
var d = $q.defer();
$http({method : 'GET', url: GET_ON_HAND_URL})
.then(function(response) {
d.resolve(response.data);
},function(error) {
d.reject(error);
});
return d.promise;
}
function getAllData() {
var promises = [];
promises.push(self.getCategories());
promises.push(self.getVendors());
promises.push(self.getProducts());
promises.push(self.getInventory());
return $q.all(promises);
}
}
Problem:
For some reason the individual http requests are sometimes coming back incomplete and I am also somehow getting Unexpected token errors where the closing bracket ] from the part of the $http request is left behind somehow. Very strange. I am sure the response JSON is correct. Here is an example request url:
http://jadran.sdsu.edu/jadrn002/servlet/surfing/data?action=vendor
What can possibly cause this type of behavior?
'$http','$q', '$filter', '$resource'
does not match your function arguments$http,$q,$filter