1

I am new to AngularJS, I successfully designed the repeated forms using nested ng-repeat. But I can't find the right way to get all values corresponding to the forms.

Here is my updated JSFiddle: http://jsfiddle.net/MrSuS/gTc5v/7/

Update: And you can see, radio input is also not working properly.

2 Answers 2

2

there is no binding in your application use ng-model to bind your field values.

if you want to design custom form depends on your dynamic data you should write a directive like this Example Form Directive

UPDATE

I think best way is repeat html form in your position. It is simple, easy and less code...

<div ng-repeat="form in forms">
    <h2>{{form.name}}</h2>
    <input type="text" ng-model="form.answer.city"><br/>
    ...

here is JSFIDDLE example...

Sign up to request clarification or add additional context in comments.

7 Comments

thanks for the example. It looks great. But it has only one form. And I have multiple forms, if i use ng-model on a element inside ng-repeat it shows same answer for all forms. Because ng-model binding will be same for all forms.
my goal is, if user wants to fill two or more forms for different persons then I should be able to get separate form values. you can check my updated JSFiddle. It must show all values one by one in alert.
thanks for the answer and your valuable time. But I forgot to tell you that the $scope.forms can have multiple forms. It changes dynamically. Sometimes size of $scope.forms can be 3 and sometimes only 1.
if we are talking about spamming same forms length does not matter... this solution can work for every length of the form array... try to add form as many as you want it will work...
|
1

Firstly use ng-model for binding. Second, use $index as array subscript for your ng-model

 ng-model="input[$index]"

1 Comment

got your idea, but not working properly. You can check my updated JSFiddle.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.