Skip to content

Instantly share code, notes, and snippets.

@lydemann
Created December 2, 2018 17:33
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 lydemann/b6e3667143b7b505d18375597e192c4d to your computer and use it in GitHub Desktop.
Save lydemann/b6e3667143b7b505d18375597e192c4d to your computer and use it in GitHub Desktop.
todo-list.service.ts
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