F
F
faragly2014-11-29 18:50:48
Angular
faragly, 2014-11-29 18:50:48

How to form ng-model with variable inside in ng-repeat loop?

Hello! There is a form, selects must have the user group ID in the name (for example, name="TASK_5", where 5 is the group ID). To send to the server, an options array is formed with all fields, so the model name should be options.TASK_ #ID# :

<tr ng-repeat="(index, taskinmodule) in usedGroups">
  <td>
    <select ng-model="options.TASKS_{{taskinmodule.ID}}" name="TASKS_{{taskinmodule.ID}}">
      <option value="">(по умолчанию)</option>
      <option ng-repeat="task in rightsData.tasks" value="{{task.id}}" ng-selected="rightsData.taskinmodule[taskinmodule.ID].ID == task.id">{{task.name}}</option>
  </select>
  </td>
</tr>

How can I get the group ID in ng-models? Sorry, I'm new.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Mikhail Osher, 2014-11-29
@miraage

ng-model="options['TASKS_' + taskinmodule.ID]"

S
Sergey, 2014-11-29
Protko @Fesor

To send to the server, an array of options is formed with all fields, so the model name should be options.TASK_#ID#:

You will not believe it, but if you need to do this for sending, then do it before sending.
And read about ng-options, you don't have to set options through ng-repeat.

F
faragly, 2014-11-29
@faragly

how to make all this work? help - jsfiddle.net/7085gjph

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question