Advertisement
Shell_Casing

articleService

Dec 12th, 2018
436
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. import { Injectable } from '@angular/core';
  2. import { HttpClient } from '@angular/common/http';
  3. import {ArticleInterface} from "./article-interface";
  4.  
  5. @Injectable({
  6. providedIn: 'root'
  7. })
  8. export class ArticleService {
  9.  
  10. serverUrl = 'http://127.0.0.1:3000/articles';
  11. articles: ArticleInterface[] = [];
  12.  
  13. constructor(private http: HttpClient) { }
  14.  
  15.  
  16. getAllArticles() {
  17. return this.http.get(this.serverUrl);
  18. }
  19.  
  20.  
  21. getOneArticle(id) {
  22. return this.http.get(`${this.serverUrl}/${id}`);
  23. }
  24.  
  25.  
  26. addArticle(title, content) {
  27. const article = { title: title, content: content };
  28. return this.http.post(`${this.serverUrl}/add`, article);
  29. }
  30.  
  31.  
  32. updateArticle(id, title, content) {
  33. const article = { title: title, content: content };
  34. return this.http.put(`${this.serverUrl}/update/${id}`, article);
  35. }
  36.  
  37.  
  38. deleteArticle(id) {
  39. return this.http.delete(`${this.serverUrl}/delete/${id}`);
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement