-1

I am trying to execute the below code where I'm trying use ng-repeat to iterate through a key:value pair. But ng-repeat is not following the index instead of rendering the second key value its rendering the thrid index

HTML:
<div ng-app ng-controller="ItemsCtrl">
    Type anything in the first box.
  <div ng-repeat="(key, value) in item">
        <input type="text" ng-model="item[key]" />

    </div>  
{{item | json}}
</div>

Javascript Controller:

function ItemsCtrl($scope) {
    $scope.item = {
        "1": "one",
        "2": "two",
        "10": "ten"};
}

Below is the jsfiddle link for the problem http://jsfiddle.net/nMjet/13/

Arvin
  • 520
  • 5
  • 13
  • 3
    Objects aren't ordered. Use an array instead if the order is important. Related: http://stackoverflow.com/questions/5525795/does-javascript-guarantee-object-property-order. – Blackhole Sep 22 '14 at 13:00

1 Answers1

0
Thanks @Blackhole.
Below the modified Code

HTML:
<div ng-app ng-controller="ItemsCtrl">
    Type anything in the first box.
  <div ng-repeat=" item in items">
        <input type="text" ng-model="item[$indexxcdxdd]" />

    </div>  
{{item | json}}
</div>

Javascript Controller:

function ItemsCtrl($scope) {
    $scope.items = ['one','two','ten'];
}
Arvin
  • 520
  • 5
  • 13