Follow the code
server.js
app.get('/list',function(req,res){
console.log('/list api run')
var data=[
{ "isActive": false, "balance": "$3,960.64", "age": 30, "eyeColor": "blue", "name": "Dawn Keith", "gender": "female", "company": "COSMOSIS", "email": "[email protected]", "phone": "+1 (839) 437-3421", "address": "392 Clifford Place, Fontanelle, Arizona, 2687"
},
{ "isActive": false, "balance": "$1,280.14", "age": 31, "eyeColor": "green", "name": "Bettie Eaton", "gender": "female", "company": "COMTREK", "email": "[email protected]", "phone": "+1 (861) 460-2317", "address": "203 Allen Avenue, Elrama, North Carolina, 4453"
},
{ "isActive": true, "balance": "$2,042.37", "age": 38, "eyeColor": "green", "name": "Margie Ayala", "gender": "female", "company": "VOIPA", "email": "[email protected]", "phone": "+1 (941) 569-2231", "address": "111 Schroeders Avenue, Suitland, Louisiana, 7042"
},
{ "isActive": false, "balance": "$3,170.35", "age": 37, "eyeColor": "blue", "name": "Baker Townsend", "gender": "male", "company": "EVIDENDS", "email": "[email protected]", "phone": "+1 (808) 500-2793", "address": "190 Just Court, Canoochee, Alabama, 325"
}]
res.json(data);
})
controller.js
var app = angular.module('appList', []);
app.factory('contactService', function($http){
var contactResponse = {};
contactResponse.list=function(){
return $http({
method: "GET",
url: "/list"
})
}
return contactResponse;
})
app.controller('contacCtrl', function($scope,contactService){
$scope.listContact=function(){
contactService.list().then(function(response){
$scope.setcontact=response;
})
}
})
Using 'success', it worked, but since this method was taken from the 1.6 api, I started using 'then', which by the way returns only 'NaN and 200'