【发布时间】:2020-09-05 20:47:28
【问题描述】:
第一次提交提交按钮后调用成功,第二次进入更新调用。如果我在提交按钮调用后单击重置按钮也会去更新 cal.l 任何人都可以帮助我吗?
组件代码
ngOnInit() {
this.resetForm();
this.refreshEmployeeList();
}
resetForm(form?: NgForm) {
if (form)
form.reset();
this.employeeService.selectedEmployee = {
_id: "",
name: "",
position: "",
office: "",
salary: null
}
}
onSubmit(form: NgForm) {
if (form.value._id == "") {
this.employeeService.postEmployee(form.value).subscribe((res) => {
this.resetForm(form);
this.refreshEmployeeList();
});
}
else {
this.employeeService.putEmployee(form.value).subscribe((res) => {
this.resetForm(form);
this.refreshEmployeeList();
});
}
}
【问题讨论】:
标签: angular