angularjs - Calling web service api -


i trying fetch web service api not able display anything, new angularjs please me. have copied controller , factory code using.

controller

app.controller('mycontroller', ['$scope', 'fetchservice', function($scope, fetchservice){     $scope.countries = fetchservice.get(); }]); 

service

var app = angular.module('app',[]); app.factory('fetchservice', ['$http', function($http){     return{         get: function(){             return $http.get('api/data4.json').success(function(response){                 return response.data;             });         }     } }]); 

the problem fetchservice.get() asynchronous (a promise returned $http), have use .then() so:

app.controller('mycontroller', ['$scope', 'fetchservice', function($scope, fetchservice){     fetchservice.get()         .then(function(response) {             $scope.countries = response;         }); }]); 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -