javascript - Angularjs ng重复错误

标签 javascript angularjs

使用 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/

相关文章:

javascript - 如何在 vb.net 的 web 浏览器中禁用消息弹出窗口

javascript - Angular ng-repeat orderBy不起作用

php - 如何从 REST 获取数据并使用 AngularJS 对其上的每个语句运行?

javascript - 等到回调结束以继续在 Angular 中执行

c# - Web Api 2 - 如何在不保存到磁盘的情况下从 HTTPGET 返回图像(来自 Azure 存储的 MemoryStream)?

javascript - 为什么这个变量在函数中未定义?

javascript - 将点击事件设置为由此事件添加的元素

javascript - D3js高亮栏一一连续

javascript - ng-class 的多个参数

AngularJS - 自定义指令范围 "&"做什么?