Dynamic variable in Angularjs

Asked

Viewed 404 times

0

I want to generate a variable dynamically in the Angularjs being an ng-repeat inside the other as below:

<tr ng-repeat="data in vm.data.data track by $index">
  <td class="center" ng-repeat="field in vm.data.field">         
    {{data + '.' + field}}
  </td>
</tr>

and is printing:

[Object Object]. name

[Object Object]. value

whereas data is an array of objects:

vm.data.data = [{name: 'Teste 1', value: 5311},{ name: 'Teste 2', value: 5245},{ name: 'Teste 3', value: 5236} ,{ name: 'Teste 4', value: 5243}]};

and

// São os campos da tabela, pois eles são dinâmicos
vm.data.field = ['name', 'value'];

1 answer

2

Solved:

<tr ng-repeat="data in vm.data.data track by $index">
  <td class="center" ng-repeat="field in vm.data.field track by $index">
    {{data[field]}}
  </td>
</tr>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.