How to set the model fields with the name 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="Send">
</form>


This option was obviously not working, but how to collect form data?
October 3rd 19 at 03:25
2 answers
October 3rd 19 at 03:27
Most likely you need to specify the index 0, 1, 2, 3, etc. in addition, you need to use the cycles of angular not to copy-paste.
October 3rd 19 at 03:29
Here's how I did in one of the 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>

Find more questions by tags Angular