简体   繁体   English

使用angularjs在ng-repeat内的输入文本中放置一个值

[英]put a value in a input text inside a ng-repeat using angularjs

HTML: 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>

Controller: 控制器:

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";
                            }



                    }
                });

Is there any way of putting a text in a input text with this code? 有没有办法用这段代码将文本放入输入文本? coz im trying to put a text using a document.getElementById("sc").value in the input inside my controller but i always got an error message saying that Cannot set property 'value' of null 因为我试图在我的控制器内的输入中使用document.getElementById("sc").value来放置文本但是我总是得到一条错误消息,说Cannot set property 'value' of null

First you should never manipulate DOM in controller, and if you want to set the value like; 首先,你永远不应该在控制器中操作DOM,如果你想设置值,那么;

<input type="number" value="100">

everything else remains same just set the value attribute to your desired value 其他一切都保持不变只需将value属性设置为您想要的值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM