I am new to Angular JS, and am trying to call Rest API using JSON data. When I run HTTP-server , am not getting back my response data.
function contacts(contactsdata) {
contactsdata.getcontacts().then(function(data) {
this.contactsinfo = data;
});
}
(function(){
var mod = angular.module('myapp');
mod.controller("contacts", contacts);
mod.service("contactsdata", function($http) {
this.getcontacts = function(){
var execute1 = $http.get('http://localhost:3000/contacts');
var execute2 = execute1.then(function(response) {
return response.data;
})
return execute2;
}
});
})();
You can try this in service
And use as