V
V
Vitaly Kuznetsov2013-10-14 17:35:19
Angular
Vitaly Kuznetsov, 2013-10-14 17:35:19

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>


This option naturally does not work, but how to collect form data?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Zaitsev, 2013-10-14
@dim_s

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.

A
Anton Rodin, 2013-11-04
@Sloot

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 question

Ask a Question

731 491 924 answers to any question