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 -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -