1

I have HTML form:

<form>
<div>Add</div>
<div>
   <input type="text" ng-model="name">
</div>
<div>
   <input type="text" ng-model="phone">
</div>
</form>

How I can clone this form that I will get two fields ng-model="name" and ng-model="text".

So, I want send to server two values of ng-model="name"

I tried:

Angular JS:

$scope.forms = 2;

HTML:

<div class="itm" ng-repeat="item in forms">
<input type="text" ng-model="name">
</div>

It gives me nothing

1 Answer 1

3

In your model:

$scope.users = [
    { 
        name: 'John',
        phone: '098097770'
    },
    {
       name: 'Alice',
       phone: '765876598'
    }
];

In your view:

<form name="editUsersForm">
    <div ng-repeat="user in users">
        <input type="text" ng-model="user.name"/>
        <input type="text" ng-model="user.phone"/>
    </div>
</form>

That's a basic rule in angular: the model is the single point of truth. The view is generated from the model.

Here's a plunkr demonstrating it.

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

7 Comments

So, I can add new element in Object and after use user
what does that mean? for each user in the array $scope.users, you will have the corresponding two inputs in the view. What you type in the inputs is bound to the user object in the array.
I need show a new input blocks when I click to link.
So, make sure the link adds a new user object to the $scope.users array. The view will update itself accordingly.
You're doing something that doesn't make any sense, and that hasn't got any resemblance to my answer and to the working plunkr I posted. WHY? ng-repeat doesn't work like you think it works. Read the documentation.
|

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.