AngularJS Tutorial - Bind input to object properties in scope








The following code shows how to Bind input to object properties in scope.

Example


<!DOCTYPE html>
<html  ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js"></script>
<!--from   w  w w . ja v a 2  s  .  co m-->
<script type='text/javascript'>

var myctrl = function($scope) {
    $scope.items = [{value: 1},{value: 2},{value: 3}];
    $scope.itemEdit1 = $scope.items;
    $scope.itemEdit2 = $scope.items;
};
</script>
</head>
<body>
  <html ng-app>
<body ng-controller="myctrl">
    <div ng-repeat="item in itemEdit1">
        <input ng-model="item.value" type="text"/>
    </div>
    Edit 1: {{itemEdit1}}<br/>
    <div ng-repeat="item in itemEdit2">
        <input ng-model="item.value" type="text"/>
    </div>
    Edit 2: {{itemEdit2}}
</body>
</html>
</body>
</html>

The code above is rendered as follows: