我正在尝试允许用户使用ngRepeat
和编辑项目列表ngModel
。(请参阅此小提琴。)但是,我尝试过的两种方法都导致了奇怪的行为:一种方法没有更新模型,另一种方法使每个keydown的表单模糊。
我在这里做错什么了吗?这不是受支持的用例吗?
这是小提琴中的代码,为方便起见进行了复制:
<html ng-app>
<head>
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.2.1/css/bootstrap-combined.min.css" rel="stylesheet">
</head>
<body ng-init="names = ['Sam', 'Harry', 'Sally']">
<h1>Fun with Fields and ngModel</h1>
<p>names: {{names}}</p>
<h3>Binding to each element directly:</h3>
<div ng-repeat="name in names">
Value: {{name}}
<input ng-model="name">
</div>
<p class="muted">The binding does not appear to be working: the value in the model is not changed.</p>
<h3>Indexing into the array:</h3>
<div ng-repeat="name in names">
Value: {{names[$index]}}
<input ng-model="names[$index]">
</div>
<p class="muted">Type one character, and the input field loses focus. However, the binding appears to be working correctly.</p>
</body>
</html>