I
I
Ivan-P2015-11-11 13:33:25
Angular
Ivan-P, 2015-11-11 13:33:25

How to control output in ng-repeat from another ng-repeat?

There is an array of objects whose properties need to be displayed in the table.

<tr ng-repeat="item in mainData.items">
    <td>{{item.name}}</td>
    <td>{{item.category}}</td>
    <td>{{item.importance}}</td>
   <td>{{item.status}}</td>
</tr>

But the properties will increase and not always all of them need to be displayed. I want to add a control array with a list of properties required for output:
<tr ng-repeat="item in mainData.items">
   <td ng-repeat="prop in mainData.itemProps">{{item.prop}}</td>
</tr>

There are empty cells. What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey, 2015-11-11
Protko @Fesor

How to control output in ng-repeat from another ng-repeat?

ngRepeat is a declarative primitive, you cannot "manage" anything through it and should not want to at all.
You must control the data you push into the viewmodel ($scope). And only so. That is, by changing the control array in js, we form a new plate and ng-repeat simply displays this plate. Everything is simple and clear, easy to debug, minimum code.

D
Dimon, 2015-11-11
@Glimor

<tr ng-repeat="item in mainData.items">
   <td ng-repeat="prop in mainData.itemProps">{{item.prop}}</td>
</tr>

To me, that's bullshit. If you need to display certain properties, and when you click on a button (or other action), display additional properties, then use the ng-show, ng-hide directives.

A
Alex, 2015-11-11
@streetflush

{{item[prop]}} ??

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question