Angularjs 你可以休息一下
我正在使用Rest在localhsost上以Json格式显示数据库中的信息。网址是 我是Angular的新手,我想做的是使用HTTPGET访问json信息 这是我的jsonAngularjs 你可以休息一下,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":"
[{"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>