rashmy
rashmy

Reputation: 21

Need to display angularjs data in my table

I am getting data in controller as below $scope.healthData = []; //declare an empty array

           $scope.init = function(){
               console.log("before function");
               $http({
                      method: 'GET',
                      url: ''
                    }).then(function successCallback(response) {

                        $scope.healthData = angular.toJson(response.data);

                    }, function errorCallback(response) {
                        alert("Trouble grabbing requested data.")
                    });

                  }

and I am trying to display my data in my jsp page as below : {{ x.name }}

<td>{{ x.componentStatus }}</td>

But I am getting below error in the console : Error: [ngRepeat:dupes] http://errors.angularjs.org/1.5.8/ngRepeat/dupes?p0=x%20in%20healthData&p1=string%3A%22&p2=%22 at angular.min.js:6

at XMLHttpRequest.t.onload (angular.min.js:103)

can anyone help me?

Upvotes: 1

Views: 473

Answers (3)

Vikash Kumar
Vikash Kumar

Reputation: 1718

in your ng-repeat just add one line

ng-repeat="data in dataset track by $index"

This error comes when you have duplicate values in your dataset.

Upvotes: 1

Matuszew
Matuszew

Reputation: 851

You have duplicates of objects ( with same content ) in your data add to ng-repeat track by $index or add track by record.id

Upvotes: 0

Atul Sharma
Atul Sharma

Reputation: 10740

Firstly their is no need to parse the data to json. By default angular only consumes data as Json.

So, just remove

$scope.healthData = response.data;

Json parsing of data.

By seeing the error.. what i feel is .. the array is containing duplicate values. In case use trackby to use some other field as key in ng-repeat.

Paste the complete code from ng-repeat and Array to get the exact problem .

Upvotes: 0

Related Questions