I feel like I'm missing something obvious here, but I can't render the JSON data to the page, only able to out put the JSON formatted data, and not just specific keys (e.g., Name: Abbey Malt).
我觉得我在这里遗漏了一些明显的东西,但是我无法将JSON数据呈现给页面,只能输出JSON格式的数据,而不仅仅是特定的键(例如,名称:Abbey Malt)。
This is my controller:
这是我的控制器:
app.controller('beerController', function($scope, $http, $modal) {
$http.get("http://api.brewerydb.com/v2/fermentables", {
params: {
key: 'xxx'
}
})
.then(function(response) {
$scope.response = response.data.name;
console.log(response);
});
};
And the HTML:
和HTML:
<div ng-controller="beerController">
<div class="container">
<h3>Latest Releases ({{currentPage}} pages)</h3>
<div class="row">
<div ng-repeat="items in response">
<li>{{data.name}}</li>
</div>
</div>
</div>
</div>
Lastly, here's a screenshot of the console and how the JSON object is structured:
最后,这是控制台的屏幕截图以及JSON对象的结构:
2 个解决方案
#1
1
Try to change your code to
尝试将代码更改为
app.controller('beerController', function($scope, $http, $modal) {
$http.get("http://api.brewerydb.com/v2/fermentables", {
params: {
key: 'xxx'
}
})
.then(function(response) {
$scope.response = response.data.data;
console.log(response);
});
};
and view
并查看
<div>
<div ng-controller="beerController">
<div class="container">
<h3>Latest Releases ({{currentPage}} pages)</h3>
<div class="row">
<div ng-repeat="item in response">
<li>{{item.name}}</li>
</div>
</div>
</div>
</div>
#2
5
put that on your controller:
把它放在你的控制器上:
$scope.items = response.data.data;
and html would be like this
和HTML会是这样的
<div ng-repeat="item in items">
<li>{{item.name}}</li>
</div>
#1
1
Try to change your code to
尝试将代码更改为
app.controller('beerController', function($scope, $http, $modal) {
$http.get("http://api.brewerydb.com/v2/fermentables", {
params: {
key: 'xxx'
}
})
.then(function(response) {
$scope.response = response.data.data;
console.log(response);
});
};
and view
并查看
<div>
<div ng-controller="beerController">
<div class="container">
<h3>Latest Releases ({{currentPage}} pages)</h3>
<div class="row">
<div ng-repeat="item in response">
<li>{{item.name}}</li>
</div>
</div>
</div>
</div>
#2
5
put that on your controller:
把它放在你的控制器上:
$scope.items = response.data.data;
and html would be like this
和HTML会是这样的
<div ng-repeat="item in items">
<li>{{item.name}}</li>
</div>