How do i return the data from my angular service

More
11 months 1 week ago #61 by vikram
vikram created the topic: How do i return the data from my angular service
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
Attachments:

Please Log in or Create an account to join the conversation.

More
11 months 1 week ago #63 by Srilakshmi Mallavolu
Srilakshmi Mallavolu replied the topic: How do i return the data from my angular service
Please login to view the answers
The following user(s) said Thank You: Babloo

Please Log in or Create an account to join the conversation.

Time to create page: 0.224 seconds
Powered by Kunena Forum