Erdem Güngör
Erdem Güngör

Reputation: 877

angularJS table array

I'm using angularJS to create an table. But it didn't works so great atm.. here my problem.

Code:

appGenerator.controller('customersCtrl', function ($scope) {
     $scope.names = [
        {"Name": "EMAIL", "StringValue": "dsa@dsada", "Type": "C"},
        {"Name": "DESC", "StringValue": "Test","Type": "C"}
        ];
});

HTML:

 <table class="table">
            <tr ng-repeat="tableItem in names">
                <td ng-repeat="item in tableItem">{{item}}</td>
            </tr>
        </table>

At the moment I get the whole Item. But I want the the "StringValue". I tested <td ng-repeat="item in tableItem">{{item.StringValue}}</td> But it doesn't works. I don't get any output. What I'm doing wrong?

Upvotes: 0

Views: 50

Answers (2)

Kulbhushan Singh
Kulbhushan Singh

Reputation: 536

Your second ng-repeat is on object's {"key": "value"} pair so ng-repeat should be as follows:

<table class="table">
    <tr ng-repeat="tableItem in names">
        <td ng-repeat="(key, value) in tableItem">{{key}}&nbsp;{{value}}</td>
    </tr>
</table>

Please refer: How can I iterate over the keys, value in ng-repeat in angular

Upvotes: 2

Ali BARIN
Ali BARIN

Reputation: 1920

You should do it like the following;

<table class="table">
  <tr ng-repeat="tableItem in names">
    <td>{{ tableItem.name }}</td>
    <td>{{ tableItem.StringValue }}</td>
    <td>{{ tableItem.Type }}</td>
  </tr>
</table>

You already iterated the names. Then you should use the object.

Upvotes: 2

Related Questions