提交表单后,输入的pristine
状态仍然是“false”。我不知道如何将 pristine
状态重置为 true。在 Angular 1 中,我会使用 $setPristine
函数。
最佳答案
我查看了 API 和开发人员指南。没有用于将输入重置为原始状态的 API。
改为developer guide on forms (“添加英雄并重置表单”部分)展示了一种通过在组件上添加事件标志来将表单重置为原始状态的机制。然后用 ngIf 将它绑定(bind)到表单标签上
active = true;
newHero() {
this.model = new Hero(42, '', '');
this.active = false;
setTimeout(()=> this.active=true, 0);
}
和
<form *ngIf="active">
这将重新生成表单,将其控件设置回原始状态。
关于angularjs - Angular 2.0 是否有类似于 Angular 1 中的 `$setPristine` 函数的东西?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35496770/