Your function getOneProduct
does not return anything, which means that it implicitly returns undefined
, therefore, an error.
$http
returns a promise, and you must return this promise from your function. So change the code to this:
productsFactory.getOneProduct = function(){
return $http({
method: 'GET',
url: '/api/products/' + $stateParams.productID
}).
success(function(data, status, headers, config){
console.log(data);
return data;
}).
error(function(data, status, headers, config){
});
}
Then in your controller:
productsFactory
.getOneProduct()
.then(response){});
source
share