Skip to content

Instantly share code, notes, and snippets.

Last active September 21, 2020 01:07
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Save Contact
public saveContact(fields: ContactFormField[], form: FormGroup): Observable<any> {
this.getFieldValuesFromForm(fields, form);
const firstName = fields.find(f => f.key === 'first_name').value;
const lastName = fields.find(f => f.key === 'last_name').value;
let contactPostBody = {
slug: `${firstName}-${lastName}-${new Date().getTime()}`,
type_slug: "contacts",
title: `${firstName} ${lastName}`,
metafields: fields,
write_key: config.writeKey
return`${this.cosmicUrl}${this.bucketSlug}/add-object`, contactPostBody);
private getFieldValuesFromForm(fields: ContactFormField[], form: FormGroup) {
fields.forEach(f => {
f.value = form.controls[f.key].value;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment