【发布时间】:2016-08-25 00:01:27
【问题描述】:
我创建了一个从 URL 调用的 API,并在点击 API 时得到响应。这是我的控制器。
adminApp.controller('PollController', function($scope,$window,$timeout, $routeParams, $http, $location) {
var story_id = 1;
$http({
method: 'get',
url: ""+story_id,
}).
success(function(response) {
// console.log(response);
//displayMessage('Sent','200px');
$scope.poll = response.polls;
console.log("======================");
console.log(response.polls);
console.log("======================");
console.log(response.polls[0].options[0].votes);
}).
error(function(response) {
console.log(response || "Request failed");
});
});
当我点击 API 时,我得到以下信息。
{
"num_polls": 1,
"polls": [
{
"total_votes": 2,
"options": [
{
"votes": "2",
"id": "2"
}
],
"id": "3"
}
]
}
我正在尝试使用工作正常的控制台日志访问 polls[0].options[0].vote,但是如何使用 AngularJS 在视图中显示它?
我试过了,但没有奏效。那么如何从 API 访问详细信息呢?
<tr ng-repeat="tableDetail in poll">
<td ng-bind="tableDetail.polls[0].options[0].votes"></td>
<td ng-bind="tableDetail.id "></td>
</tr>
【问题讨论】: