Vishnu Rapposol
Vishnu Rapposol

Reputation: 33

How to get the text in a dynamic text box of a form in Angular Js?

Thank you. In my form there are some dynamic input text boxes created by using ng-repeat. How to get the values of these text boxes when submit the form using Angular js?

<form ng-submit="submit()">
 <div ng-repeat="opt in option">
  <input type="text" name=""> 
 </div>
</form>

Upvotes: 0

Views: 1161

Answers (2)

Hmahwish
Hmahwish

Reputation: 2232

Use ng-model to bind the input values and $index for that particular index in the repeated values.

 $scope.inputData = [];

inputData will have the binded values.

 <form ng-submit="submit()">
   <div ng-repeat="opt in option">
     <input type="text" name="" ng-model="inputData[$index]"> 
   </div>
 </form>

Upvotes: 1

nikhil mehta
nikhil mehta

Reputation: 1032

Not sure of what you want but guess this will help you

<div ng-app="myApp" ng-controller="myController">
<input type="text" ng-model="data[$index].Name" ng-repeat="num in numbers track by $index"/>
<p ng-repeat="dataObj in data track by $index">
  {{dataObj.Name}}
</p>
</div>

I have created a fiddle here

Upvotes: 1

Related Questions