使用 patchValue 方法更新表单值时,表单变脏?

When using patchValue method to update form value, form becomes dirty?

我必须知道 patchValue 方法的概念。使用补丁值方法更新表单值时,表单变脏.

// using this way

setTimeout(() => {
      this.skillForm.patchValue({
        date: [new Date()],
      });
    }, 1000);

样本:click here

但是,如果我像下面这样使用表格就不会变脏

setTimeout(() => {
       // workaround for this scenario
      this.skillForm.controls['date'].patchValue(new Date());

    }, 1000);

样本 link : click here

回答

updated sample click here

你必须这样使用,它不会添加 ng-dirty class

 setTimeout(() => {
       this.skillForm.patchValue({
       //compare this
              date: new Date(),
          });
    }, 3000);