[英]put a value in a input text inside a ng-repeat using angularjs
HTML:
<form role="form" ng-submit="submit3(qgradecontainer)">
<div data-ng-repeat="qgrade in qgradecontainer">
<div class="form-group">
<label>Quiz #{{array[$index]}}</label>
</div>
<div class="form-group">
<label>Correct Answers</label>
<input type="number" min="0" max="{{array2[$index]}}" class="form-control" placeholder="Number of items: {{array2[$index]}}" ng-model="qgrade.score" id="sc{{$index}}">
</div>
</div>
<div class="text-center">
<input type="submit" class="btn btn-success" value="Save">
</div>
</form>
控制器:
gradingSheetSrvc.getNumOfitems($scope.qtbl).then(function(msg){
if(msg.data){
$scope.array2 = $.map(msg.data[0], function(value, index) {
return [value];
});
$scope.ind = $.map(msg.data[0], function(value, index) {
return [index];
});
//console.log($scope.array2[1]);
for(var i=1; i<=len; i++){
$scope.qgradecontainer.push({'id':$scope.array[i-1],'sid':id,'col':$scope.ind[i-1],'tbl':$scope.qtbl,'numofitems':$scope.array2[i-1]});
document.getElementById("sc"+i--).value = "Test";
}
}
});
有沒有辦法用這段代碼將文本放入輸入文本? 因為我試圖在我的控制器內的輸入中使用document.getElementById("sc").value
來放置文本但是我總是得到一條錯誤消息,說Cannot set property 'value' of null
首先,你永遠不應該在控制器中操作DOM,如果你想設置值,那么;
<input type="number" value="100">
其他一切都保持不變只需將value屬性設置為您想要的值
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.