0

I have a MongoDB Collection like this:

{ "Auftragsnr" : "456", "Positionnr" : "Babba Jabba Frabba", "__v" : 0, "_id" : ObjectId("53d8ef77888a15ed69dd16a5") }

{ "Auftragsnr" : "123", "Bonusposition" : "test", "Geschaeftsfeld" : "test3", "Positionnr" : "Anton Cesar Berta2222", "__v" : 0, "_id" : ObjectId("53d8eeec888a15ed69dd16a4") }

Since I want to go Schemaless in the future, I don't want to access the collection like this in my ViewModel, which works:

  <li ng-repeat="friend in friends">
        <input type="text" ng-model="friend.Auftragsnr">
        <input type="text" ng-model="friend.Positionnr">
        <input type="text" ng-model="friend.Bonusposition">
        <input type="text" ng-model="friend.Geschaeftsfeld">
  </li>

How can I iterate through my documents and map each value to an input field without having to define the JSON member in ng-model (e.g. "friend.Auftragsnr")?

Stephan Kristyn
  • 15,015
  • 14
  • 88
  • 147
  • See http://stackoverflow.com/questions/15127834/how-can-i-iterate-over-the-keys-value-in-ng-repeat-in-angular – Goodzilla Aug 22 '14 at 09:11

1 Answers1

0

This should work :

<div ng-repeat="friend in friends">
  <li ng-repeat="(key, value) in friend">
    <input type="text" ng-model="friend[key]">
  </li>
</div>
Goodzilla
  • 1,483
  • 11
  • 17