gpt4 book ai didi

javascript - Angularjs ng重复错误

转载 作者:行者123 更新时间:2023-11-30 15:39:01 26 4
gpt4 key购买 nike

使用 Angularjs 我无法执行 ng-repeat。首先 ng-repeat 工作正常,接下来工作不正常

HTML代码

<div class="col-xs-12" ng-app="myAns" ng-controller="myCtrl">
<table class="table">
<tr><td ng-repeat="fullname in team1_name">{{fullname}}</td></tr>
<tr><td ng-repeat="strike in team1_strike">{{strike}}</td></tr>
<tr><td ng-repeat="wickets in team1_wickets">{{wickets}}</td></tr>
</table>
</div>

Js代码

<script>
var app = angular.module('myAns', []);
app.controller('myCtrl', function($scope, $http, $timeout) {
$timeout(function() {
$http({
url: 'cricketAnswerSuggestionApi.php',
method: "POST",
withCredentials: true,
headers: {
'Content-Type': 'application/json; charset=utf-8'
}
}).then(function (response) {
$scope.team1_name = response.data.team_1.fullname;
$scope.team1_strike = response.data.team_1.strike_rate;
$scope.team1_wickets = response.data.team_1.wickets;
});
});
});
</script>

JSON 响应链接

https://jsfiddle.net/rijo/aapfa0sL/

请任何人帮助如何使用 angularjs 打印此值...谢谢大家

最佳答案

因为你有一些重复的数据

team1_striketeam1_wickets 使用 track by $index

试试这个,

 <div class="col-xs-12" ng-app="myAns" ng-controller="myCtrl">
<table class="table">
<tr>
<td ng-repeat="fullname in team1_name">{{fullname}}</td>
</tr>
<tr>
<td ng-repeat="strike in team1_strike track by $index">{{strike}}</td>
</tr>
<tr>
<td ng-repeat="wickets in team1_wickets track by $index">{{wickets}}</td>
</tr>
</table>

DEMO

关于javascript - Angularjs ng重复错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41095216/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com