0

I was woundering how i can access JSON that has dynamic names:

AngularJS http-get:

.then(function (response) {
                    $scope.GTMcontainersAccount = response.data;
                    console.log($scope.GTMcontainersAccount);

Response JSON:

{
    "Account2": [{
        "accountId": "*******",
        "containerId": "*******",
        "name": "Container23"
    }, {
        "accountId": "*******",
        "containerId": "*******",
        "name": "Container2"
    }],
    "Account 1": [{
        "accountId": "*******",
        "containerId": "*******",
        "name": "Container1"
    }]
}

My goal here is to use ng-repeat in a table to show like this:

AccountName | AccountId | containerId | name
  Account2  |  *******  |   *******   | Container23
  Account2  |  *******  |   *******   | Container2
  Account1  |  *******  |   *******   | Container1

How can use the controller to output something like this table?

1 Answer 1

1

Try like to this

<table>
<thead>
  <tr>
    <th>AccountName</th>
    <th>AccountId</th>
    <th>containerId</th>
       <th>name</th>
  </tr>
</thead>
<tbody ng-repeat="(k,v) in data">
  <tr ng-repeat="(k1,v1) in v">
    <td>{{k}}</td>
    <td >{{v1.accountId}}</td>
    <td >{{v1.containerId}}</td>
    <td >{{v1.name}}</td>
  </tr>
</tbody>

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

1 Comment

Awsome!! Worked like Charm. Thanks @Hadi

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.