Ng-form to submit dynamically generated form without specific ng-model

Edited code to better ask question
And thanks for all the help from everyone so far! I have some dynamically generated input fields that do not have a fixed number of inputs and would like to present them as you go ....
how can I pass input from input text fields from a dynamically generated form?
Hope my question makes sense?
the form I am trying to submit is as follows: How do I pass values ​​to create ()? the pass is currently not working ... and the links to $ scope.a gets 'undefined' ... :( Please help to thank you!

<form ng-submit="create(a)">
    <div class="module-head text-center">
        <b class="lead">{{ module.heading }}</b>
        <input class="btn" type="submit" id="submit" value="+"/>
    </div>
    <div class="module-body">
        <div class="control-group" ng-repeat="field in module.fields">
            <label class="control-label">{{field.name}}</label>
            <div class="controls">
                <input type="text" name="fields"
                 ng-model="a[$index]" ng-init="a[$index]=field.data">
            </div>
          </div>
      </div>
</form>

      

+3


source to share


3 answers


How about something like this?

<form ng-submit="create()">
    <input class="btn" type="submit" id="submit" value="+"/>
    <div ng-repeat="item in items">
        <input type="text" name="fields" ng-model="itemArray[$index]">
    </div>
</form>

      

When you submit this, itemArray will have all the model values ​​of the input fields.



To assign initial values ​​to input fields.

<input type="text" name="fields" ng-model="a[$index]" ng-init="a[$index]=item"/>

      

0


source


I'm not sure if I got your question, but if you want to access the values ng-model

in the controller, you can create the linearray

$scope.arr=[];

And in your form, use it like

<div ng-repeat="item in items">
    <input type="text" name="fields" ng-model="arr[item]"/>
</div>

      



Thus, $scope.arr

all your input values ​​will have.

See fiddle: http://jsfiddle.net/Sourabh_/HB7LU/13274/

0


source


You would try to do this:

<form ng-submit="create()">
    <input class="btn" type="submit" id="submit" value="+"/>
    <div ng-repeat="item in items">
        <input type="text" name="fields" ng-model="items[$index]">
    </div>
</form>

      

0


source







All Articles