I am trying to get Json data from REST Api ("http://jsonplaceholder.typicode.com/posts/") using angularJS custom service but it is not showing the data. Although when I am directly typing the url in the browser it shows some data.
Here is the angular service code.
angular.module('myapp.service',[])
       .service('testService', function ($http) {
     //get All NewsLetter
     this.getPosts = function () {
         return $http.get('http://jsonplaceholder.typicode.com/posts');
     };
     });
and controller
angular.module('myapp.controller',[])
       .controller('testController',function($scope,testService){
        $scope.posts={};
 function GetAllPosts() {
               var getPostsData = testService.getPosts();
               getPostsData.then(function (post) {
                   $scope.posts = post.data;
               }, function () {
                   alert('Error in getting post records');
               });
           }
       });
When I debugged it in the browser . it shows service function is returning undefined data.
Although when I tried to get the data directly in the controller using the code
angular.module('myapp.controller',[])
       .controller('testController',function($scope,testService,$http){
         $http.get('http://jsonplaceholder.typicode.com/posts')
        .success(function (data) {
        $scope.posts=data ;
    });  
       });
it works fine,Can any one please tell me where i am making the mistake in the service.
I have used a parent module having all the dependency injections
angular.module('myapp',['myapp.controller','myapp.service']);  
