gpt4 book ai didi

Angular 重置 react 形式

转载 作者:行者123 更新时间:2023-12-05 09:11:28 26 4
gpt4 key购买 nike

发送后我试图重置我的表单,但只有值设置为空。

component.html

  <div *ngIf="!loading" fxLayout="row" class="note-textarea">
<form fxFlex fxLayout="column" fxLayoutGap="10px" [formGroup]="noteForm">
<mat-form-field fxFlex>
<textarea matInput #note rows="1" maxlength="100" placeholder="Note" formControlName="description"></textarea>
<mat-hint align="end">{{note.value?.length || 0}}/100</mat-hint>
<mat-error *ngIf="noteForm.get('description').errors && noteForm.get('description').touched">description is required</mat-error>
</mat-form-field>
<div fxFlex>
<button mat-stroked-button class="save-btn" (click)="insertNote()">Save</button>
</div>
</form>
</div>

component.ts

  noteForm: FormGroup = this.formBuilder.group({
description: new FormControl(null, Validators.required)
})
 insertNote() {
// bunch of code

this.noteForm.reset();

}
}

问题是输入字段被标记为脏,如下所示:

enter image description here

最佳答案

尝试使用按钮 type="reset" 选项

<button type="reset">Reset</button> 

Stackblitz Example

关于 Angular 重置 react 形式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60054578/

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