Shamoon
Shamoon

Reputation: 43609

ng-model inside ng-repeat is losing focus

In my JavaScript, I have

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

My HTML is

<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>

Whenever I type something, it loses focus in the input box.

Upvotes: 0

Views: 77

Answers (1)

Shamoon
Shamoon

Reputation: 43609

Turns out I needed to do:

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

Upvotes: 1

Related Questions