如何使用ng-repeat与JSON对象?

时间:2017-12-30 22:07:25

标签: javascript angularjs json

它不起作用

HTML

<div ng-repeat="item in items">
 <p>{{forecasts.list[$index].main.temp}}</p>
</div>

JS

$http({
 method: 'GET',
 url: 'http://api.openweathermap.org/data/2.5/forecast?q='+$scope.city +'&units=metric&cnt=3&appid=338d293879598530ec8cef82c5d375d4'
}).then(function (success) {
 console.log("nice");
 $scope.forecasts = success.data;
 }, function (error) {
   console.log("error");
});

如何重写ng-repeat并使用此对象 JSON

1 个答案:

答案 0 :(得分:0)

您必须遍历$scope.forecasts.list属性。我建议您阅读AngularJS文档中如何使用ng-repeat

<div ng-repeat="temperatures in forecasts.list">
  <p>{{ temperatures.main.temp }}</p>
</div>