ng-repeat中的ng-model正在失去焦点

时间:2015-12-19 14:06:10

标签: javascript angularjs

在我的JavaScript中,我有

$scope.newQuestion = {
  answers: []
};

我的HTML

<div class="row" ng-repeat="answer in newQuestion.answers">
  <div class="input-field col m12">
    <input id="answer{{ $index }}" type="text" class="validate" ng-model="newQuestion.answers[$index]">
  </div>
</div>

每当我输入内容时,它都会在输入框中失去焦点。

1 个答案:

答案 0 :(得分:1)

原来我需要这样做:

<div class="row" ng-repeat="answer in newQuestion.answers track by $index">