Pds Ink
Pds Ink

Reputation: 765

passing array value to element inside ng-repeat

ok, i have something like this:

<td>{{row.sku}}</td>
<td>{{row.name}}</td>
<td>{{row.type}}</td>
<td>{{row.category.label}}</td>
<td class="text-center">{{row.price | currency : "€"}}</td>
<td>{{row.description}}</td>
<td>{{row.state}}</td>
<td class="text-center">{{row.amount}}</td>

and i want to change this thing in something like this

<td ng-repeat="row in displayed">{{row.[value]}}</td>

can you suggest me if there is a way?

Upvotes: 1

Views: 1285

Answers (2)

Guenter Guckelsberger
Guenter Guckelsberger

Reputation: 940

See the following simple example. demo plnkr

angular.module("myApp",[])
.controller("MyController", function($scope) {
  $scope.displayed = [
    {"one":"one", "two":"two", "three":"three"},
    {"one":"1", "two":"2", "three":"3"}];
})
<html ng-app="myApp">

  <head>
    <script data-require="[email protected]" data-semver="1.4.7" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.js"></script>
    <link rel="stylesheet" href="style.css" />
    <script src="script.js"></script>
  </head>

  <body>
    <h1>Test table</h1>
    <table ng-controller="MyController">
      <tr ng-repeat="row in displayed">
        <td ng-repeat="(key,value) in row">{{row[key]}}</td>
      </tr>
    </table>
  </body>

</html>

Upvotes: 0

Michele Ricciardi
Michele Ricciardi

Reputation: 2117

You can do it as follows:

<table>
  <tr ng-repeat="row in vm.array">
    <td ng-repeat="(key,value) in row ">{{value}}</td>
    </tr>
</table>

here a plunkr

Upvotes: 1

Related Questions