Tengo la siguiente estructura de datos:
{
current: { Number: '8', AnotherNumber: 123 },
}
{
current: { Number: '9', AnotherNumber: 456 },
}
Quiero en vista angular imprimir en una tabla:
Number AnotherNumber
8 123
Estoy intentando con esto, pero muestra todo el objeto actual
<li ng-repeat="friend in friends">
<span ng-repeat="(key, value) in friend">
{{friend.current}}
</span>
</li>
2 respuestas
Un solo elemento friend
en su caso es un objeto {current:{}}
para iterar a través de claves y valores, debe hacer algo como:
<li ng-repeat="friend in friends">
<span ng-repeat="(key, value) in friend.current">
{{key}} {{value}}
</span>
</li>
http://plnkr.co/edit/hWKl262YIi0IBhIebJGz?p=preview ejemplo de trabajo plnkr
El código debería tener este aspecto:
<table>
<tr>
<th>Number</th>
<th>AnotherNumber</th>
</tr>
<tr ng-repeat="friend in friends">
<td>{{friend.current.Number}}</td>
<td>{{friend.current.AnotherNumber}}</td>
</tr>
</table>
Sin relación con la pregunta, pero puede hacer esto por brevedad:
<table>
<tr><th>Number</th><th>AnotherNumber</th></tr>
<tr ng-repeat="friend in friends" ng-init="c=friend.current">
<td>{{c.Number}}</td><td>{{c.AnotherNumber}}</td>
</tr>
</table>
ACTUALIZACIÓN:
Si lo desea, puede iterar "a ciegas" sobre las teclas, pero eso dará como resultado que las columnas se ordenen alfabéticamente (a menos que agregue más código para especificar su orden explícitamente):
<table>
<tr>
<th ng-repeat="key in firends[0]">{{key}}</th>
</tr>
<tr ng-repeat="friend in friends">
<td ng-repeat="(key value) in friends">{{value}}</td>
</tr>
</table>
Consulte, también, esta breve demostración .
Preguntas relacionadas
Nuevas preguntas
javascript
Para preguntas sobre la programación en ECMAScript (JavaScript / JS) y sus diversos dialectos / implementaciones (excepto ActionScript). Incluya todas las etiquetas relevantes en su pregunta; por ejemplo, [node.js], [jquery], [json], etc.