ng-model,ng-repeat和输入有困难我试图允许用户使用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>
3 回答
- 3 回答
- 0 关注
- 478 浏览
添加回答
举报
0/150
提交
取消