在Angular 6(响应式表单)中单击按钮时是否重置表单组?

时间:2018-10-03 05:44:34

标签: angular forms button refresh reset

单击按钮后,我试图清除表单值。 下面显示了HTML和Angular组件。在同一按钮上,单击我要重置或刷新值。 谢谢。

 onAddClientNeeds() {
        
        this.listOfNeedsAssessment.push(this.needsAssessment.value);
        this.isNeedsAssessmentAdded = true;
    }
<div [formGroup]="needsAssessment" class="main-container">
    <div class="header-section">
    <div class="flex-container">
        
            <div class="edit-section">
                <p class="edit-title">Mental Health</p>
                <div class="edit-body">
                    <select class="form-control" (change)="onchange($event)" (blur)="onchange($event)" id="mental_health">
                        <option selected value="0">Select Option</option>
                        <option *ngFor="let mentalHealth of mentalHealthList" value={{mentalHealth.Id}}>{{mentalHealth.Item}}</option>
                    </select>
                </div>
            </div>
            <div class="edit-section">
                <p class="edit-title">Persistant Pain</p>
                <div class="edit-body">
                    <select class="form-control" (change)="onchange($event)" (blur)="onchange($event)" id="persistant_pain">
                        <option selected value="0">Select Option</option>
                        <option *ngFor="let persistantPain of persistantPainList" value={{persistantPain.Id}}>{{persistantPain.Item}}</option>
                    </select>
                </div>
            </div>
            
        <div class="button-select">
            <button type="button" class="create-button" (click)="onAddClientNeeds()">Add Needs Assessment Outcomes</button>
        </div>
    </div>
</div>

1 个答案:

答案 0 :(得分:0)

只需调用函数reset()

onAddClientNeeds() {
  if (this.needsAssessment.valid) {
    this.needsAssessment.reset();     
  }
}