提交表单后,输入框的
pristine
状态仍为“false”。我不知道如何将pristine
状态重置为true。在Angular 1中,我会使用$setPristine
函数。有一个拉取请求正在等待添加https://github.com/angular/angular/pull/6679 还可以参考这个相关问题https://github.com/angular/angular/issues/4933
通常使用的解决方法是重新创建表单。
active = true;
newHero() {
this.model = new Hero(42, '', '');
this.active = false;
setTimeout(()=> this.active=true, 0);
}
并且
<form *ngIf="active">
这会重新生成表单,并将其控件重置为原始状态。