这是一个奇怪的问题.代码很简单:
HTML代码:
<body ng-controller="MainCtrl">
  <ul ng-repeat="name in names">
    <input type="text" ng-model="name" />
  </ul>
</body>
角度代码:
app.controller('MainCtrl', function($scope) {
    $scope.names = ["aaa","bbb","ccc"];
});
在现场演示网址是:http://plnkr.co/edit/2QFgRooeFUTgJOo223k9?p=preview
我不明白为什么输入控件无法编辑,我无法输入新字符或删除字符.
由于范围继承,这是一个常见问题.你的每一个names都是一个原语,所以ng-repeat它使自己的范围项与原始连接,但是如果每个names都是一个对象,则ng-repeat范围项将是对原始对象的引用
 [{name:"aaa"},{name:"bbb"},{name:"ccc"}];
始终使用dotin ng-model是一个有用的经验法则
<div ng-repeat="item in names">
      <input type="text" ng-model="item.name"/>
    </div>
阅读有关angular github wiki的这篇文章,详细解释:
https://github.com/angular/angular.js/wiki/The-Nuances-of-Scope-Prototypal-Inheritance
| 归档时间: | 
 | 
| 查看次数: | 7645 次 | 
| 最近记录: |