Problem using $http.get in a function

95 views
Skip to first unread message

Alejo Ribes

unread,
Sep 19, 2016, 5:04:01 AM9/19/16
to AngularJS
Hi, i get this error on run a function with $http.get: "angular.js:12477 TypeError: $http.get(...).succes is not a function" when $http works in a controller


I need a button to call rest service, i using with ng-click directive but on call the function, show the error.

Code in a controller:
var app = angular.module("StorePrincipal", [])
app.controller("listAll", function ($scope, $http){
$http.get("../api/get-products")
.success(function(data, status, headers, config){
var arrayProducts = [];
$scope.arrayProducts = []
for(var i = 0; i < data.length; i++){
$scope.arrayProducts.push(data[i].attribs[0])
$scope.arrayProducts[i].urlImg1 = "../img/products/" + data[i].attribs[0].img1
$scope.arrayProducts[i].id = data[i]._id
console.log("ID: " + $scope.arrayProducts[i].id);
}
console.log($scope.arrayProducts)
})
.error(function(data, status, headers, config){
alert(status);
})

$scope.removeProduct = function (productID){
console.log(productID);
$http.get("../api/remove-product/" + productID)
.succes(function(data){
console.log("Product Deleted")
})
.error(function(data, status, headers, config){
alert(status);
})
}
});

Sander Elias

unread,
Sep 19, 2016, 9:05:52 AM9/19/16
to AngularJS
Hi Alejo,

.success is a remainder. $http should be used the .then instead. 
Your fiddle gives a 404 on the resource, so I can't use it to dig into your actual issue.

Regards
Sander
Reply all
Reply to author
Forward
0 new messages