0

I have a factory that returns a JSON object using $resource.get request but I cannot get some data from my ngresource factory:

HTML

<body ng-app="myApp" ng-controller="myCtrl" >
<table border="1">
    <tr>
        <th>Name</th>
        <th>city</th>
    </tr>
    <tr ng-repeat="x in data.records">
        <td style="padding: 20px">{{records.Name}}</td>
        <td style="padding: 20px">{{records.City}}</td>
    </tr>
</table>
</body>

JS:

angular.module('myApp',['ngResource']);

angular.module('myApp').controller("myCtrl",function (yourService,$scope) {

});

angular.module('myApp').

factory('yourService', ["$resource", function($resource,$scope){

    return $resource("http://www.w3schools.com/angular/customers.php").get().$promise
        .then (function (data){


    });
    return data;
}]);
PMerlet
  • 2,568
  • 4
  • 23
  • 39
  • 1
    Possible duplicate of [Multiple parameters in AngularJS $resource GET](http://stackoverflow.com/questions/30604693/multiple-parameters-in-angularjs-resource-get) – Hadi J Jan 25 '17 at 09:40

2 Answers2

0

Change your factory to

factory('yourService', ["$resource", function($resource, $scope) {
  return $resource("http://www.w3schools.com/angular/customers.php").get().$promise
    .then(function(data) {
       return data;
    });
}]);

and inside your controller get the data:

yourService.then(function(data) {
  console.log(data.records);
});

See fiddle

Dario
  • 6,152
  • 9
  • 39
  • 50
0

Your return data is not in correct place. return data in inside response.

  factory('yourService', ["$resource", function($resource) {
  return $resource("http://www.w3schools.com/angular/customers.php").get().$promise
    .then(function(data) {
       return data;
    });
}]);
Manikandan Velayutham
  • 2,228
  • 1
  • 15
  • 22