1

How to get dynamic array input value in angularjs .i want to collect all values of input in angular js function and retun from function so that the return value can be displayed any where in the page .Is it possible because it is possible in php that if i submit form with array of input like $cat in this case ,and can be displayed anywhere in the page .

<input type="text" name="cat[]" ng-model="cat">
<input type="text" name="cat[]" ng-model="cat">
<input type="text" name="cat[]" ng-model="cat">
<input type="text" name="cat[]" ng-model="cat" >

1 Answer 1

3

In your controller $scope.cat = ["a","b","c","d"] and in your view:

<input type="text" name="cat[]" ng-model="cat[0]">
<input type="text" name="cat[]" ng-model="cat[1]">
<input type="text" name="cat[]" ng-model="cat[2]">
<input type="text" name="cat[]" ng-model="cat[3]">

or dynamic with ng-repeat

<div ng-repeat="c in cat">
  <input type="text" value="{{c}}" ng-model="cat[$index]">
</div>
Sign up to request clarification or add additional context in comments.

2 Comments

@ Kreienbring how to collect values u mentioned in or code
because of the "2-way-data-binding" the array entries will be updated as soon as you type something in the input fields.

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.