0

AngularJs 源代码:

<html ng-app>
  <body ng-controller="Controller">
    <div ng-init="numbers=[11,22,33]">
       <div ng-repeat="n in numbers">
         <input type="text" ng-model="n"/> [{{n}}]
       </div>
    </div>
    <script>
        function Controller($scope) {}
    </script>
  </body>
</html>

当我更改输入的值时,右侧的文本不会更新。哪里错了?

现场演示在这里:http: //jsfiddle.net/Freewind/TZwxy/

您可以更改输入中的值并查看。

4

1 回答 1

1

尝试使用一组对象:

function Controller($scope) {
  $scope.numbers = [{value: 11 }, {value: 22 }, {value: 33 }];
}

<html ng-app>
  <body ng-controller="Controller">
    <div>
       <div ng-repeat="n in numbers">
         <input type="text" ng-model="n.value"/> [{{n.value}}]
       </div>
    </div>
  </body>

</html>

请参阅jsFiddle

于 2013-01-10T10:30:08.977 回答