Angularjs ng-repeat dynamic property -
<div (ng-repeat='item in items') > {{item.name}} //works {{item["name"]}} // works </div>
how repeat item[property] dynamically without using ".name" or ['name']?
to dynamically go through properties, you're going need call object.keys(item)
, iterate through them. it's best prune data within controller, minimize finagling you'll need within html.
if want try within html-angular structures, define:
$scope.returnallkeyvalues = function(obj){ var x = object.keys(obj), arr = []; for(var = 0; i<x.length; i++){ arr.push(obj[x[i]]); } return arr; }
what function takes in json object, parses through , collects values every key within it.
then, within html, can write this:
<h3>fifa mactch summary:</h3> <div ng-app ng-controller="myctrl"> <ul> <li ng-repeat="item in items"> <span ng-init="keyvalues = returnallkeyvalues(item)"> <span ng-repeat="keyvalue in keyvalues">{{key}} </span> </span> </li> </ul> </div>
here see, within original ngrepeat, initialized array keyvalues values item's keys via function defined above. then, ng-repeat through that, , have printed without knowing are.
here fiddle working: http://jsfiddle.net/rkykr/2771/