Last active
October 1, 2020 03:23
-
-
Save Qarun-Qadir-Bissoondial/7634fcb13ad6441131b0485d8f8eb27e to your computer and use it in GitHub Desktop.
Basic Todo service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { HttpClient } from '@angular/common/http'; | |
import { Injectable } from '@angular/core'; | |
export interface Todo { | |
userId: number, | |
id: number, | |
title: string, | |
completed: boolean; | |
} | |
@Injectable({ | |
providedIn: 'root' | |
}) | |
export class TodoService { | |
url: string = 'https://jsonplaceholder.typicode.com/todos'; | |
constructor(private http: HttpClient) {} | |
getAllTodos() { | |
return this.http.get(this.url) | |
} | |
getSingleTodo(id: number) { | |
return this.http.get(`${this.url}/${id}`); | |
} | |
createTodo(item: Todo) { | |
return this.http.post(this.url, item); | |
} | |
updateTodo(id: number, updatedItem: Todo) { | |
return this.http.put(`${this.url}/${id}`, updatedItem); | |
} | |
deleteTodo(id: number) { | |
return this.http.delete(`${this.url}/${id}`); | |
} | |
displayError(message: string) { | |
console.log(message); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment