我有一个输入字段,一旦填充了一个数字,就会填充该额外输入字段的数量。我不知道如何在这些生成的输入字段中插入值。任何帮助表示赞赏,哦,我确实尝试了各种事情,甚至使用 angular.element,或者仅使用 jquery,但失败了,所以欢迎任何关于如何做到这一点的解释。
这是我的jsfiddle,这里是 c/p-ed 代码:
<div ng-controller="MyCtrl">
<input type="text" ng-model="cntInputs" placeholder="#Inputs"><br/>
<input ng-repeat="i in getTimes()" type="text" placeholder="{{i}}" id="input_{{i}}">
<ul>
<li ng-repeat="j in getTimes()">
Inputed value is: {{getValue(j)}}
</li>
</ul>
</div>
js:
var myApp = angular.module('myApp', []);
function MyCtrl($scope) {
$scope.cntInputs = 0;
$scope.getTimes=function(){
var a = new Array();
for(var i=1; i <= $scope.cntInputs; i++)
a.push(i);
return a;
};
$scope.getValue = function(id){
//here get the value of that inserted in the element with the id of "input_" + id
return angular.element("input_" + id);
}
}