Search code examples
javascriptangularjs2-way-object-databinding

how to bind angularjs objects to their keys and values


I read through some articles on angular model binding, and just out of curiousity, I was wondering if its possible to bind keys to input too,

http://jsfiddle.net/x3azn/jM28y/4/

so I am hoping ot update the main arr through the input boxes and achieve 2 way key-binding.

Is this possible?


Solution

  • as explained here Binding inputs to an array of primitives using ngRepeat => uneditable inputs, yes you can, but not that way

    try this

    function ctrl($scope) {
    $scope.arr = [{name:'1', lastname: '2'},
                  {name:'3', lastname: '4'},
                  {name:'5', lastname: '6'}]
    }
    
    <div ng-repeat="person in arr">
        <input type="text" ng-model="person.name" />
        <input type="text" ng-model="person.lastname" />
    </div>
    

    http://jsfiddle.net/jM28y/5/