我正在使用AngularJS JavaScript尝试连接两个变量以生成或使用ng-bind-html
,因为我需要在用户点击按钮时分配一些动态值。这是我的方法:
$scope.addRow = function(verifier){
$scope.count = 1;
console.log(verifier);
if(!angular.isUndefined(verifier)) {
$scope.row1= $sce.trustAsHtml('<input type="text" class="form-control" required="required">');
$scope.row2= $sce.trustAsHtml('<input type="text" class="form-control" required="required">');
$scope.row3= $sce.trustAsHtml('<input type="text" class="form-control" required="required">');
$scope.row4= $sce.trustAsHtml('<input type="text" class="form-control" required="required">');
$scope.row5= $sce.trustAsHtml('<input type="text" class="form-control" required="required">');
$scope.row6= $sce.trustAsHtml('<input type="text" class="form-control" required="required">');
$scope.row7= $sce.trustAsHtml('<input type="text" class="form-control" required="required">');
}else{
alert('You can not add new line to balance null object');
}
}
答案 0 :(得分:1)
我花了一段时间才了解你的需要。你需要这样写:
$scope.count = 1;
$scope["row" + $scope.count] = $sce.trustAsHtml('<input type="text" class="form-control" required="required">');