ng-repeat 및 $ index를 사용하여 양식 입력란의 이름에 넣을 항목의 색인을 얻으려는 것 같습니다. 정확히 무엇을하려고하는지 잘 모르겠지만 잘하면 올바른 방향으로 가게됩니다.
EDIT : 또한 입력의 이름 = ""은 각도를 사용하여 양식을 제출할 때 부적합합니다. , 당신은 $ scope에서 변경하는 전체 객체를 가져 와서 AJAX를 통해 보낼 수 있습니다.
HTML
<form name="publisherForm" ng-submit="formSubmit()">
<div class="inputbox" ng-repeat="publisherParam in publisherParams">
<div>
<label>{{publisherParam.label}}</label>
</div>
<div>
<!-- use $index to get the index of the item in the array -->
<!-- note, no {{}} inside of the ng-model tag.
That's being $eval'ed so no {{}} needed -->
<input type="text" name="publisherParam_label_{{$index}}" ng-model="publisherParam.label" required />
</div>
</div>
<!-- just an add button so you can see it work -->
<button type="button" ng-click="addPublisherParam()">Add</button>
<!-- your submit button -->
<div class="submitbox">
<button class="purple-btn" type="submit ng-disabled="publisherForm.$invalid">
Add Network
</button>
</div>
</form>
JS
app.controller('YourController', function($scope) {
//this is the array you're displaying
$scope.publisherParams = [
{ label: 'First Label' },
{ label: 'Second Label' }
];
//just an indexer
var p = 0;
$scope.addPublisherParam = function(){
//add a new publisher param.
$scope.publisherParams.push({ label: 'New Label ' + p++ });
};
$scope.formSubmit = function(){
//do something here.
};
});
사실 내가 NG 모델 = "publisherParam1"나 뭐 그런 식으로 뭔가를해야하지만 그때 동적 다른 입력을 추가하는 경우 나는 ng-model = "publisherParam2"가 필요합니다. 그리고 인덱스를 추가하는 방법이나 ng 모델을 구별하는 방법을 찾을 수 없습니다 – Mythriel