1

I try to load a table in HTML from Ajax json, using Angular and ng-repeat. My problem is that the JSON is a bit complicated and I don't know how to access "informationstyp", which is what I want to display in the table. The root of the JSON ("values") is a list. Next level ("informationstyper") is also a list.

How can I get "informationstyp" into the table? What should I write instead of {{data.arendeslagId}} in my html?

What I want in my table is:

FK1002

FK1003

FK1004

Thank you for your help.

My html:

        <table class="table table-hover">
            <thead>
            <tr>
                <th>Arendeslagid</th>
            </tr>
            </thead>
            <tbody>
            <tr ng-repeat="data in infotyper">
                <td>{{data.arendeslagId}}</td>
            </tr>
            </tbody>
        </table>

My JavaScript:

    $scope.infotyper = "";

    $scope.invoke = function() {
        $.ajax({
               "cache": false,
               "async": true,
               "crossDomain": true,
               "url": url",
               "method": "POST",
               "headers": {
                   "cache-control": "no-cache",
               },
            success: function (response) {
                   $scope.infotyper= response;
               }
           });
        };

My JSON-response:

enter image description here

2
  • you can use $http service methods in angular instead of jquery ajax. Commented Jun 4, 2017 at 23:08
  • @hasan Thank you, I have now changed it to $http Commented Jun 16, 2017 at 19:59

1 Answer 1

3

Try to change this:

success: function (response) {
  $scope.infotyper= response;
}

To this:

success: function (response) {
  $scope.infotyper= response.values;
  $scope.$apply();
}

If you are using AngularJS I strongly suggest you to use $http service instead of jQuery for AJAX requests

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

3 Comments

That's not working either. How can I get into the next level in JSON ("informationstyper")?
That field is an Array. So you need another ng-repeat for cycling inside those elements. For example: <tr ng-repeat="data in infotyper"> <td>{{data.arendeslagId}}</td> <td ng-repeat="typer in data.informationstyper">{{typer.informationstyp}}</td> </tr>
Thank you, that's exactly what I needed!

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.