2

I have an Array in my controller. On the basis of that Array I'm generating Input fields On my page.

My AngularJs code

var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope) {
  $scope.names = ['morpheus', 'neo', 'trinity'];
});

And on page I'm generating my input fields

<form name="myForm1" ng-controller="MainCtrl">
     <div ng-repeat="gg in names">
       <input type="text" ng-model="control[index]"/>
     </div>
     <input type="submit" value="submit"/>
</form>

Now it generating ng-model for each textbox are control[index]

but I want to generate ng-model for each textbox like

control[0]
control[1]
control[2]

Plunker

1
  • You need to use $index to refer to index. But, you should know that your "model" is your array of names. Are you trying to create a copy of the model? Commented Dec 22, 2014 at 6:25

1 Answer 1

3

you have to use

<input type="text" ng-model="control[$index]"/>

and there is no scope variable called control so you need to define the scope variable also, as below

$scope.control = {};

here is the updated Plunker

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.