1

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?

4
  • 2
    Follow the white rabbit Commented Dec 21, 2016 at 14:15
  • You have duplicates in the model you're trying to bind and you're not managing them correctly. There's a lot of info out there on this topic. Just search for the error. Commented Dec 21, 2016 at 14:18
  • tried this.no luck. the error is gone, but data is not displaying Commented Dec 21, 2016 at 14:32
  • Can you post your code that shows the entire table including the ng-repeat? Commented Dec 21, 2016 at 14:41

3 Answers 3

1

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.

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

Comments

0

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 .

3 Comments

Yeah Thanks, I am able to print my data now. Again, I am using c3 charts to display the same data.But my json data is not available outside
use $scope.healthData and write the chart code in the controller iteself. Variable will not be accessible outside controller.
yes my controller scope is there until the end of the js file. when i just exit the http method , when i alert , i am not getting $scope.healthData
0

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

Comments

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.