javascript - Angular JS data response undefined -


this question has answer here:

i new angular js, , trying call rest api using json data. when run http-server , not getting 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 in service

       this.getcontacts = function(){            return $http.get('http://localhost:3000/contacts');        }); 

and use

contactsdata.getcontacts().then(function(response){     this.contactsinfo = response.data; }); 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -