即使设置为原始值,angular2 formcontrol仍然很脏 [英] angular2 formcontrol stays dirty even if set to original value
问题描述
当我在输入字段中更改一个值时,相应的表格控件被设置为脏。当我恢复我的更改时(通过在输入字段中输入),表单控件保持脏。这是打算,这是一个错误还是我做错了什么?
When I change a value in an input field, the corresponding form-control is set to dirty. When I revert my change (by typing in the input field) the form-control stays dirty. Is this intended, is this a bug or do I do something wrong?
推荐答案
好吧,它的目的是以这种方式工作:
Well, yes it's intended to work that way since:
如果用户已更改,则控件为
脏 strong> UI中的价值。 (文档条目)
A control is
dirty
if the user has changed the value in the UI. (docs entry)
..并且如果该值与起始值不同,则不是。
..and not if the value is different from the starting value.
如果您希望恢复肮脏状态,您可以使用 markAsPristine()
( docs entry a>)在 AbstractControl
上。 (例如,通过点击按钮或订阅 valueChanges
In case you want to revert the dirty state you could use the markAsPristine()
(docs entry) on your AbstractControl
. (eg trigger it by click on a button or when subscribing to the valueChanges
observable of the AbstractControl
and compare the new value to a previously stored one...)
这篇关于即使设置为原始值,angular2 formcontrol仍然很脏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!