Nitin Agarwal Nitin Agarwal - 7 months ago 35
HTML Question

Storing the data in array using ng-model

I want to store the data in an array using the ng-model. I have an controller as RegisterController in which i inject

$scope
with ng-model name as user i.e.
$scope.user={}
.Here i am reading the data from form input element and submitting the data that has
ng-model="user.name"
and now i want to store that name or the multiple values in that user object.

<form class="well" align="center">
<input ng-model="user.name" name="name" type="text"><br/>
<input ng-model="user.name" name="mobile" type="text"><br/>
<input ng-model="user.name" name="mail" type="mail"><br/>
<input ng-model="user.name" type="password" name="otp"><br/><br/>

<button type="button">Sign Up</button>
<a href="#/login">Login</a><br><br>
</form>


and the controller is

app.controller("RegisterController",function($scope){

$scope.user={};
})


Now let me know to store the data in the user that as array with example

ANK ANK
Answer

I think your doing a small mistake. Instead of sending the same ng-model="user.name" send is as,

<form class="well" align="center">
<input ng-model="user.name" name="name"  type="text"><br/>
<input ng-model="user.mobile name="mobile"  type="text"><br/>
<input ng-model="user.mail" name="mail"  type="mail"><br/>
<input ng-model="user.password" type="password" name="otp"><br/><br/>

<button type="button">Sign Up</button>
<a href="#/login">Login</a><br><br>
</form>

And you have to send that ng-model to the function as in button

 <button type="button" ng-click="signup(user)">SignUp</button>

now you can able to get what you want