This is how I use $resource
In Companyservice.js
this.queryItem = function (){
var deferred = $q.defer();
setTimeout(function() {
// deferred.notify('Saving data..');
var items = Company.query({},function() {
deferred.resolve(items.d.results);
}, function(error){
deferred.reject(error);
});
}, 1000);
return deferred.promise;
};
and in controller
var promise = CompanyService.queryItem();
promise.then(function(response){
// for each item in response, push item to array
angular.forEach(response, function(item){
$scope.companys.push(item);
});
}, function(reason){
console.log(reason);
});
Instead of pushing the returned item(s) to an array, you should set $scope.company = response;
Hope this helps!