Try this
if ($.isEmptyObject(specialProducts)) {
$resource('index.php/products/featureProducts').query().$promise.then(function(data){
angular.foreach(data,function(item) {
specialProducts.push(item);
});
});
}
But in your controller you need to know when the data was returned from remote call for which you can watch over the specialProducts
array.
Update: Better would be to use promises, but in this case
$scope.specialProducts = specialProductFactory.getFeatureProducts();
would fill the array in future. To know when you need to watch
$scope.$watchCollection("specialProducts",function(data) { //Called when data updated});
I strongly suggest you work with promise based API and use the then
methods to get handle async responses.