gpt4 book ai didi

angular - 何时应将 FormControl 标记为原始状态?

转载 作者:行者123 更新时间:2023-12-04 15:29:15 28 4
gpt4 key购买 nike

我讨论了表单应该如何与同事合作,我们对后端驱动的输入字段应该如何响应用户输入有不同的想法。

此讨论基于 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 documentationpristine 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.
*/

这里要注意两点:
  • 用户尚未更改 UI 中的值
  • 对控件值的编程更改保持原始状态
  • 关于angular - 何时应将 FormControl 标记为原始状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61599684/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com