<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<script type="text/javascript">
function fetchRecords($http){
$http.get("http://jsonplaceholder.typicode.com/posts")
.then(function (response) {
this.records = response.data})
}
function recordsCtrl($scope, list){
$scope.names = list.records
}
var newApp = angular.module('newApp',[])
newApp.service('list',fetchRecords)
newApp.controller('recordsCtrl',recordsCtrl)
</script>
</head>
<body ng-app="newApp" >
<div ng-controller="recordsCtrl">
<table>
<tr>
<th>Number</th>
<th>id</th>
<th>Title</th>
<th>Body</th>
</tr>
<tr ng-repeat='name in names' >
<td>{{name.userId}}</td>
<td >{{name.id}}</td>
<td >{{name.title}}</td>
<td >{{name.body}}</td>
</tr>
</table>
</div>
</body>
</html>
Not able to display records which am getting in response , how to use service in ANgular js ,please let me know . I am trying to keep the $http in custom service and from there I want to pass that response to my $scope . can some one help me