0

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?

2 Answers 2

2

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.

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

2 Comments

Oh god! Thanks :D so easy ^^
You can even iterate on object {"key": "value"} pair, please refer: stackoverflow.com/questions/33434003/angularjs-table-array/…
2

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

2 Comments

You can iterate keys and values of the object like that. But what did you with this attribute 'ng-repeat="item in tableItem"'? There is no tableItem data in ngRepeat. So why did you iterate it? You should fix this code.
<td >{{ value.Name}} </td> with this <td> tag it works. Thanks :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.