为什么更改值时不会更新嵌套作用域中的模型?

时间:2013-01-10 09:48:17

标签: binding nested angularjs

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/

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

1 个答案:

答案 0 :(得分: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

相关问题