如何获取ng-repeat中动态添加的输入的值



我试图获得单击框时创建的输入值。这些输入在一个ng-repeat中。我试着在ng-click内发送项目,但由于它在ng-repeat之外,它将不起作用。我似乎不知道如何得到每个输入的值。任何帮助都将非常感激!

<div class="tagBox" ng-repeat="item in inputs">
    <input ng-model="itemValue"/>
</div>
<span class="btn btn-link topic-link" ng-click="addInput(item)">
     Add Another Topic
</span>

JS

$scope.inputs = []
$scope.addInput = function(){
    $scope.inputs.push({})
}

现在看起来是将所有输入绑定到$scope.itemValue。获取该信息的最佳方法是初始化$scope。itemValue作为数组,然后执行如下操作:

<div class="tagBox" ng-repeat="item in inputs">
    <input ng-model="itemValue[$index]">
</div>

那么你可以在$范围内获得所有的值。itemValue数组。

最新更新