Vikram created a new topic ' How do i return the data from my angular service' in the forum. 1 year ago

Hi,
In the following code below
var app = angular.module('postModule', []);
app.controller('postController', function ($scope,postService)
{
$scope.result = postService.GetPost();
console.log($scope.result);

});
app.service('postService', function ($http)
{
this.GetPost = function()
{
$http.get(" jsonplaceholder.typicode.com/posts ")
.then(function (response)
{
console.log(response.data);
var data = response

.data;
return data;
});

}
});
when i call the getPost method of postService it goes and fetches the data but when i return data from getPost method value that get stored in $scope.response is undefined , can any one help me in this

Read More...

.Chandra(Admin) is friends with Vikram