1

This is My result in console logJSon data Hi i am Trying to Bind JSON object Data to a table.my issue is i am able to bind entire json object {{metric}} but failed to load each atttribute of json object i.e.,{{metric.EmpId}}. finally from my observation i found when the converted json object is directly asigned to

$scope.Employees="Employee": [ {"EmpId": "4", "Name": "Chris", "Sex": "Male", "Phone": [ { "_Type": "Home", "__text": "564-555-0122" }, { "_Type": "Work", "__text": "442-555-0154" } ], "Address": { "Street": "124 Kutbay", "City": "Montara", "State": "CA", "Zip": "94037", "Country": "USA" } } ] }

the output is working as i expected but when i assign the direct result

i.e,$scope.Employees=response;it is not working what might be the issue

    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
    <script src="xml2json.js"></script>
     <script>
                var app = angular.module('httpApp', []);
                app.controller('httpController', function ($scope, $http) {
                    $http.get("File1.xml",
                            {
                                transformResponse: function (cnv) {
                                    var x2js = new X2JS();
                                    var aftCnv = x2js.xml_str2json(cnv);
                                    return aftCnv;
                                }
                            })
                    .success(function (response) {
                        console.log(response);
                        $scope.Employees = response;
                        console.log($scope.Employees);
                    });
                });
            </script>
 <div>
            <div ng-app="httpApp" ng-controller="httpController">
                <div ng-repeat="metric in Employees">

                    {{ metric}}
                    <br />
                    <br />
                    <table>
                        <tr ng-repeat="metric in Employees">
                            {{metric}}
                             <td ng-repeat="cell in metric">{{cell}}</td>
                            <td>{{cell.EmpId}}</td>
                            <td>{{metric.Name}}</td>
                        </tr>
                    </table>
                </div>
            </div>

6
  • 2
    can you show the json itself? Commented Jun 23, 2016 at 7:46
  • 1
    what does your employees response look like ? Commented Jun 23, 2016 at 7:46
  • 1
    are you getting data in console.log? Commented Jun 23, 2016 at 7:47
  • 1
    please provide the json object structure. Commented Jun 23, 2016 at 7:48
  • Can you please show us the JSON Commented Jun 23, 2016 at 8:13

1 Answer 1

1

Assuming your json has the following format:

$scope.Employees = {
    "Employee": [
        {
            "EmpId": 1,
            "Name": "Sam"
        },
        {
            "EmpId": 2,
            "Name": "Lucy"
        }
    ]
};

You probably would want to do this:

<div ng-repeat="employeeList in Employees">
    <table>
        <tr ng-repeat="employee in employeeList">
             <td>{{employee.EmpId}}</td>
             <td>{{employee.Name}}</td>
        </tr>
    </table>
</div>
Sign up to request clarification or add additional context in comments.

10 Comments

i tried the same its not working.actualy my xml data is converting in to json which looks like above image entire json object can be retrive but the particular details cannot that is EmpId,Name etc
Is your json a string?
I checked your json on jsoneditoronline.org and it had some unknown extra characters. I got it working on my machine after removing those.
just checked with my json on jsoneditoronline.org and its working good there is no problem with json object .There is some thing going wroing at ng-repeat and my JSon is an Object
Thanks for u r continues supportCheck the jsfiddle:jsfiddle.net/a5khgLeL/2 when i put json object its working good but where the error."The is no problem with json object i hope"
|

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.