angular - 防止输入更改导致表单变脏(Angular 5.2)

标签 angular angular-forms dirty-data

有没有一种简单的方法可以防止输入控件弄脏其父窗体? 我可以通过构建一个没有 controlValueAccessor 的自定义标签来做到这一点,但我想知道是否有更简单的方法。

在我的一个表单中间,我有一个输入按钮旁边有一个数字。输入只是指定我要添加到一组事物中的某种类型的项目的数量。您指定多少的输入与表单是否应被视为脏无关,因为在单击添加按钮之前表单没有“更改”,此时一堆项目被添加到集合中并且我传播更改从那里开始。

最佳答案

如果你使用模板驱动的表单,你可以使用

[ngModelOptions]="{standalone: true}"

这是专门为您的场景定义的。来自文档:

standalone: Defaults to false. If this is set to true, the ngModel will not register itself with its parent form, and will act as if it's not in the form. This can be handy if you have form meta-controls, a.k.a. form elements nested in the tag that control the display of the form, but don't contain form data.

关于angular - 防止输入更改导致表单变脏(Angular 5.2),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49079590/

相关文章:

angular - 以 Angular 形式保留 http 调用的顺序

javascript - AngularJS - 在不删除验证错误的情况下设置原始表单

angular - Dartlang:pubspec.yaml中的Dev Transformers

html - boolean 值不变

javascript - 密码未显示

html - 如何选择 Angular 6 中的所有复选框?

angular - 如何在 Angular 6 中构建具有多个组件的表单?

java - 如何使用java清理脏文本

angular - <app-root> 没有被填满