Created
December 2, 2018 17:33
-
-
Save lydemann/b6e3667143b7b505d18375597e192c4d to your computer and use it in GitHub Desktop.
todo-list.service.ts
This file contains hidden or 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'; | |
import { TODOItem } from '@app/shared/models/todo-item'; | |
import { of } from 'rxjs'; | |
import { delay, first } from 'rxjs/operators'; | |
@Injectable() | |
export class TodoListService { | |
private _todoList: TODOItem[] = []; | |
public get todoList(): TODOItem[] { | |
return this._todoList; | |
} | |
private todoListUrl = '//localhost:8080/api/todo-list'; | |
private freshTodoListUrl = '//localhost:8080/api/fresh-todo-list'; | |
constructor(private httpClient: HttpClient) {} | |
public getAndSetTodoList() { | |
this.httpClient | |
.get<Array<TODOItem>>(this.todoListUrl) | |
.pipe(first()) | |
.subscribe((data) => { | |
this._todoList = data; | |
}); | |
} | |
public getAndSetNewTodoList() { | |
this.httpClient | |
.get<Array<TODOItem>>(this.freshTodoListUrl) | |
.pipe(first()) | |
.subscribe((data) => { | |
this._todoList = data; | |
}); | |
} | |
public addTodo(todo: TODOItem) { | |
return of(null).pipe(delay(2000)); | |
} | |
public updateTodo(todo: TODOItem) { | |
return of(null).pipe(delay(2000)); | |
} | |
public deleteTodo(id: string) { | |
return of(null).pipe(delay(2000)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment