防止输入变化导致表单变脏(Angular 5.2)

Prevent input change from causing form to dirty (Angular 5.2)

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

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

如果您使用 template-driven 表格,您可以使用

[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.