我想在用于保存角形联系人的同一保存按钮上更新表单的预填充编辑数据
如何实现?
我尝试添加,但是将更新后的数据作为单独的记录添加,而不是更新现有数据。
o
nSubmit() {
this.submitted = false;
if (this.contactForm.invalid) {
UIkit.notification({ message: 'Empty Contact cannot be added', status: 'warning' });
return;
}
this.submitted = true;
this.contacts = this.contactService.addContact(this.contactForm.value);
UIkit.notification({ message: 'Contacts Added Successfully', status: 'success' });
UIkit.modal('#formmodal').hide();
}
addContact(contact: IContacts) {
const newId = this._contacts.length + 1;
/* console.log(contact.phoneNum); */
this._contacts.push({
id: newId,
firstName: contact.firstName,
lastName: contact.lastName,
companyName: contact.companyName,
jobTitle: contact.jobTitle,
email: contact.email,
phoneNum: contact.phoneNum,
labels: contact.labels,
notes: contact.notes
});
return this._contacts;
}
预期输出应为更新现有联系人。