Html 动态添加行时不提交角度表单
我试图开发一个共有6个输入字段的页面-2个常量和4个动态。单个表单需要发送带有动态标记行的数据,这些行将由用户选择添加 视图: 问题是: 当我单击-保存按钮时,动态行的表单数据不会显示出来 在控制台中。此外,当添加多行时,-delete按钮也会执行此操作 不删除单个行。默认情况下,最后一行将被删除。可能是什么原因 代码中的问题Html 动态添加行时不提交角度表单,html,angularjs,Html,Angularjs,我试图开发一个共有6个输入字段的页面-2个常量和4个动态。单个表单需要发送带有动态标记行的数据,这些行将由用户选择添加 视图: 问题是: 当我单击-保存按钮时,动态行的表单数据不会显示出来 在控制台中。此外,当添加多行时,-delete按钮也会执行此操作 不删除单个行。默认情况下,最后一行将被删除。可能是什么原因 代码中的问题 使用array.pop时,它将删除数组中的最后一个元素。解决方案是通过ng click从视图中传递元素索引,并基于索引拼接数组,这样元素将从数组中删除 查看 <di
使用array.pop时,它将删除数组中的最后一个元素。解决方案是通过ng click从视图中传递元素索引,并基于索引拼接数组,这样元素将从数组中删除 查看
<div class="col-sm-2"><button ng-click="delMarks($index)"> Delete</button></div>
更新
var std=angular.module(“studentsApp”,[]);
标准控制器(“家庭控制器”,功能($scope){
$scope.showMarks=false;
$scope.studentMarks=[];
$scope.addMarks=函数(){
$scope.showMarks=true;
var rowcontut=$scope.studentMarks.length+1;
$scope.studentMarks.push({
子节点:$scope.formData.regno,
子二:0,
次三级:0,
子文件夹:0,
});
//console.log(rowConut);
//log($scope.studentMarks);
};
$scope.delMarks=函数(索引){
rowcontut=$scope.studentMarks.length-1;
$scope.studentMarks.splice(索引1);
//$scope.studentMarks.pop();
//console.log(rowConut);
//log($scope.studentMarks);
};
$scope.saveFullForm=函数(){
//
log($scope.formData);
log($scope.marks);
log($scope.studentMarks);
};
});代码>
学生表格
删除
添加
编辑
拯救
印刷品
使用array.pop时,它将删除数组中的最后一个元素。解决方案是通过ng click从视图中传递元素索引,并基于索引拼接数组,这样元素将从数组中删除
查看
<div class="col-sm-2"><button ng-click="delMarks($index)"> Delete</button></div>
更新
var std=angular.module(“studentsApp”,[]);
标准控制器(“家庭控制器”,功能($scope){
$scope.showMarks=false;
$scope.studentMarks=[];
$scope.addMarks=函数(){
$scope.showMarks=true;
var rowcontut=$scope.studentMarks.length+1;
$scope.studentMarks.push({
子节点:$scope.formData.regno,
子二:0,
次三级:0,
子文件夹:0,
});
//console.log(rowConut);
//log($scope.studentMarks);
};
$scope.delMarks=函数(索引){
rowcontut=$scope.studentMarks.length-1;
$scope.studentMarks.splice(索引1);
//$scope.studentMarks.pop();
//console.log(rowConut);
//log($scope.studentMarks);
};
$scope.saveFullForm=函数(){
//
log($scope.formData);
log($scope.marks);
log($scope.studentMarks);
};
});代码>
学生表格
删除
添加
编辑
拯救
印刷品
它不工作。如果我们添加3行并删除第二行,第三行也会被删除,第二行的数据在删除后会复制到第一行。添加一行后不会被删除。您好@nooball,对不起,我的错误。它应该只是$scope.studentMarks.splice,而不是$scope.studentMarks=$scope.studentMarks.splice。请参阅更新的答案谢谢@digit的更新。还有一件事,如果输入元素被破坏,当点击编辑按钮时,如何编辑这些数据。或者使用“保存”按钮保存。您的意思是用户无法输入文本吗?它不起作用。如果我们添加3行并删除第二行,第三行也会被删除,第二行的数据在删除后会复制到第一行。添加一行后不会被删除。您好@nooball,对不起,我的错误。它应该只是$scope.studentMarks.splice,而不是$scope.studentMarks=$scope.studentMarks.splice。请参阅更新的答案谢谢@digit的更新。还有一件事,如果输入元素被破坏,当点击编辑按钮时,如何编辑这些数据。或使用“保存”按钮保存。您的意思是用户无法输入文本吗?
<div class="col-sm-2"><button ng-click="delMarks($index)"> Delete</button></div>
$scope.delMarks = function (index){
rowConut = $scope.studentMarks.length -1;
$scope.studentMarks.splice(index,1);
console.log(rowConut);
console.log($scope.studentMarks);
};