У меня есть форма, которая onSubmit должна сбрасывать значение определенного поля формы. До сих пор я пробовал следующее:
TS-файл:
ngOnInit() {
this.loading = true;
this.getIncident();
this.loading = true;
})
this.addCommentsForm = new FormGroup({
comment: new FormControl(''),
number: new FormControl('')
})
}
onSubmit() {
let putData = Object.assign({}, this.addCommentsForm.value);
console.info('form, ', putData)
this.uploading = true;
this.commentProgress.progress = 100;
this.service.putIncidentsComments(putData, this.s_id).subscribe((response: any) => {
console.info("comment sent");
this.getIncidentComments();
this.uploading = false;
this.commentProgress.progress = 0;
this.addCommentsForm.reset();
}, (errorResponse: any) => {
console.info(errorResponse); //On unsuccessful response
this.error = true;
this.uploading = false;
});
}
}
строка: this.addCommentsForm.reset(); сбрасывает всю форму, а я просто хочу сбросить поле комментария? есть идеи?





Вы можете получить formControl и сбросить его:
this.addCommentsForm.get('comments').reset();