Answer the question
In order to leave comments, you need to log in
How to set a model for fields named field[]?
<form>
<input type="text" name="answer[]" ng-model="data.answer[]">
<input type="text" name="answer[]" ng-model="data.answer[]">
<input type="text" name="answer[]" ng-model="data.answer[]">
<input type="text" name="answer[]" ng-model="data.answer[]">
<input type="text" name="answer[]" ng-model="data.answer[]">
<input type="submit" value="Отправить">
</form>
Answer the question
In order to leave comments, you need to log in
Most likely, you need to specify an index - 0, 1, 2, 3, etc. In addition, you need to use cycles from angular so as not to copy-paste.
Here's what I did in one of my projects
<div ng-repeat="line in data.answer">
<input type="text" ng-model="data.answer[$index]"/>
<span class="icon-remove" ng-click="data.answer.splice($index, 1)"></span>
</div>
<span class="icon-plus" ng-click="data.answer.push('')"></span>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question