我讨论了表单应该如何与同事合作,我们对后端驱动的输入字段应该如何响应用户输入有不同的想法。
此讨论基于 Angular's definition of pristine
"pristine" means the user hasn't changed the value since it was displayed in this form.
因此,假设用户有一个自动完成输入来查找附近的机场,当用户选择一个选项时,我们设置
FormControl
的值。到所选选项。我的理解是,由于用户选择了该选项,因此用户更改了 FormControl。
我的同事的理解是更改是程序化的,而
FormControl
基于某些后端进程进行更新,因此该值是“受信任的”并被标记为原始值。有没有更具体的原始定义?一种考虑后端流程或程序化输入的方法?
最佳答案
我想答案是in the documentation的pristine
AbstractControl
的属性(property):
/**
* A control is `pristine` if the user has not yet changed
* the value in the UI.
*
* @returns True if the user has not yet changed the value in the UI; compare `dirty`.
* Programmatic changes to a control's value do not mark it dirty.
*/
这里要注意两点:
关于angular - 何时应将 FormControl 标记为原始状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61599684/