Skip to content

Instantly share code, notes, and snippets.

@BetterProgramming
Created August 26, 2019 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BetterProgramming/2f77c61f8d0b40ab128368d030661147 to your computer and use it in GitHub Desktop.
Save BetterProgramming/2f77c61f8d0b40ab128368d030661147 to your computer and use it in GitHub Desktop.
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { environment } from 'src/environments/environment';
@Injectable({
providedIn: 'root'
})
export class ContactService {
constructor(
private http: HttpClient
) { }
getContacts() {
return this.http.get(`${environment.apiUrl}/contacts`);
}
addContact(contactData) {
return this.http.post(`${environment.apiUrl}/contacts`, contactData);
}
editContact(contactData) {
return this.http.put(`${environment.apiUrl}/contacts/${contactData.id}`, contactData);
}
deleteContact(contactId) {
return this.http.delete(`${environment.apiUrl}/contacts/${contactId}`);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment