I am working on a project where I have an Array in my controller. This Array is being used to dynamically generate input fields on the page.
Here is a snippet of my AngularJs code:
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.names = ['morpheus', 'neo', 'trinity'];
});
After setting up the controller, I proceed to generate the input fields on the page using the following code:
<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>
Currently, each textbox is being generated with ng-model
as control[index]
. However, I would like to change this so that the ng-model for each textbox follows this pattern:
control[0]
control[1]
control[2]
If you'd like to see the code in action, check out this Plunker.