1

Using Angularjs I can't do ng-repeat. First ng-repeat is working fine next is not working fine

Html code

<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 code

<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 response link

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

Kindly anyone help how to print this value using angularjs ... Thanks for all

0

1 Answer 1

2

Because you have some duplicate data

Use track by $index for team1_strike and team1_wickets

Try this,

 <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

Sign up to request clarification or add additional context in comments.

2 Comments

@nikky who said i did? probably because you have posted the same
i was using track by $index for first ng-repeat also.it doesnt make any difference from your answer?Will it work with your answer if team1_name have duplicates?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.