[英]One form by row (fields for every column) with buttons for each: how to manage the dirty state?
I would like to handle the dirty state for every single row I have in my table. 我想处理表中每一行的脏状态。 Unfortunately, adding a form around a would break the table, and I can't create it inside since I have a field for every different column.
不幸的是,在a周围添加一个表单会破坏表格,并且由于在每个不同的列都有一个字段,所以无法在其中创建表格。 My last column for each row contains buttons: Delete and Update.
每行的最后一列包含按钮:删除和更新。 Update appears only if one of the field of this row has been made dirty.
仅当此行的一个字段被弄脏时,才会显示更新。
Somehow, it works already but I am checking each .pristine for every field on that row ( #name="ngModel"
). 某种程度上,它已经可以工作了,但是我正在检查该行(
#name="ngModel"
)上每个字段的每个.pristine。 My rows are created through something like *ngFor="let row of rows"
. 我的行是通过
*ngFor="let row of rows"
。 I believe it would be better to check the .dirty
or .pristine
on a form rather than on every single element. 我相信最好在表单上而不是在每个元素上检查
.dirty
或.pristine
。
Also, if I actually to the update, there is no way I can remove that .dirty status (I tried replacing the data for that row by removing from the array and re-adding it but it is still dirty). 另外,如果我确实要进行更新,则无法删除该.dirty状态(我尝试通过从阵列中删除并重新添加该行来替换该行的数据,但它仍然很脏)。
Is there a technique to go around that? 有解决这个问题的技术吗?
You could use ngModelGroup around each of your rows. 您可以在每行中使用ngModelGroup。 Then you can check the dirty flag for the group.
然后,您可以检查该组的脏标志。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.