Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 你可以休息一下_Angularjs_Json_Rest - Fatal编程技术网

Angularjs 你可以休息一下

Angularjs 你可以休息一下,angularjs,json,rest,Angularjs,Json,Rest,我正在使用Rest在localhsost上以Json格式显示数据库中的信息。网址是 我是Angular的新手,我想做的是使用HTTPGET访问json信息 这是我的json [{"horse":{"age":"6yo","breeder":"David Harvey","countryBred":"(IRE)","horseAge":"6yo","horseId":1,"horseName":"Brain Power","owner":"Michael Buckley","pedigree":"

我正在使用Rest在localhsost上以Json格式显示数据库中的信息。网址是

我是Angular的新手,我想做的是使用HTTPGET访问json信息

这是我的json

[{"horse":{"age":"6yo","breeder":"David Harvey","countryBred":"(IRE)","horseAge":"6yo","horseId":1,"horseName":"Brain Power","owner":"Michael Buckley","pedigree":"Kalanisi","sex":"(08May11 b g)","trainer":{"days":9,"location":"Lambourn","seaonWinners":119,"seasonStrikeRate":27,"stake":-69.77,"trainerId":2,"trainerName":"Nicky Henderson"},"trainerName":"Nicky Henderson"}},
这是我用Angular试过的,但它并没有显示任何东西。非常感谢您的帮助,谢谢

var horseApp = angular.module('horseApp', []);
   horseApp.controller('HorseCtrl', function ($scope, $http){
      $http.get('http://localhost:8080/restful-services/api/getAllHorses').success(function(data) {
      $scope.horse = data;
   });
});

马
年龄
名称
饲养员
{{horse.age}
{{horse.horesName}}
{{马.繁殖者}

更改ng中的变量,重复如下操作

<tr ng-repeat="h in horses">
    <td>{{h.horse.age}}</td>
    <td>{{h.horse.horesName}}</td>
    <td>{{h.horse.breeder}}</td>
</tr>
  • $http.success
    已过时,请使用
    然后使用
    。看
  • 您希望迭代数组,因此修改ng repeat应该做到这一点,现在您指向一个无效的属性年龄,因为
    horse
    是一个数组。
    的更好名称是
修改代码

  horseApp.controller('HorseCtrl', function ($scope, $http){
    $http.get('http://localhost:8080/restful-services/api/getAllHorses')
        .then(function(response) {
      $scope.horse = response.data;
    });
  });
Html


{{item.age}
{{item.horesName}
{{item.breeder}}

Change$scope.horses=response.data;
  horseApp.controller('HorseCtrl', function ($scope, $http){
    $http.get('http://localhost:8080/restful-services/api/getAllHorses')
        .then(function(response) {
      $scope.horse = response.data;
    });
  });
<tr ng-repeat="item in horse">
    <td>{{item.age}}</td>
    <td>{{item.horesName}}</td>
    <td>{{item.breeder}}</td>
</tr>