如何在ng-repeat中获得动态添加输入的值?

时间:2015-09-28 14:01:57

标签: angularjs ng-repeat angularjs-ng-model

我正在尝试获取单击框时创建的输入值。这些输入在ng-repeat内。我尝试在ng-click内部发送项目,但因为它在ng-repeat之外它不起作用。我似乎无法弄清楚如何获得每个输入的值。 任何帮助都会非常感激!

HTML

<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({})
}

1 个答案:

答案 0 :(得分:0)

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

class CucumberClazz {

   Set<Plugin> plugins;

   public doRequest() {
     for(Plugin plugin: plugins) plugin.beforeRequest();
     /* Rest of the code */
   } 
}

然后,您可以在$ scope.itemValue数组中获取所有值。

相关问题