我需要使用ng-repeat显示数组中的一些数据,每个数据都有其自己的输入字段。我需要动态添加这些输入,然后通过调用一个函数从它们中获取数据。
//controller for my modal
app.controller('myCtrl1', function($uibModal, $uibModalInstance,
$window, $http, data) {
var pc = this;
pc.childTradeValues = data.childTradeVal.child;
pc.arr = [];
pc.confirmTrade = function (object) { //Confirm Trade Function
console.log(object);
// $uibModalInstance.close();
};
pc.cancel = function () {
$uibModalInstance.dismiss('cancel');
};
});
//Code of my Modal where im creating inputs
<div class="modal-body">
<div>
<div ng-repeat="childTradeValue in pc.childTradeValues track by $index">
<label>{{ childTradeValue.email }}</label>
<input type="number" ng-model="arr[$index]" class="form-control" placeholder="Enter Quantity">{{arr[$index]}}
</div>
</div>
</div>
<div class="modal-footer">
<div class="col-md-12 textAlignCenter">
<button class="btn btn-success" ng-click="pc.confirmTrade($index)">
Confirm
</button>
</div>
//my Array
$scope.childTradeVal = {"child":[{"id":1,"email":"test@gmail.com"},
{"id":2,"email":"test2@gmail.com"},
{"id":3,"email":"test3@gmail.com"}]};