首页 > 解决方案 > 从引导模式中的 ng-repeat 输入获取 ng-model 值

问题描述

我需要使用 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"}]};

标签: angularjsangularjs-ng-repeat

解决方案


推荐阅读