Skip to content

Instantly share code, notes, and snippets.

@orlando-c-h
Last active November 9, 2017 15:55
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 orlando-c-h/e8c95bed68354eec6f96472a83be7d34 to your computer and use it in GitHub Desktop.
Save orlando-c-h/e8c95bed68354eec6f96472a83be7d34 to your computer and use it in GitHub Desktop.
import { Injectable } from '@angular/core';
import { Todo } from './to-do';
import { TODO_ITEMS } from '../../api/to-do-data';
@Injectable()
export class TodoService {
pItems: Todo[] = TODO_ITEMS;
constructor() { }
getTodosFromData(): Todo[] {
return this.pItems;
}
addTodo(todo: Todo) {
this.pItems.push(todo);
}
updateTodo(todo: Todo) {
const index = this.pItems.map(x => x.id).indexOf(todo.id);
this.pItems[index] = todo;
}
deleteTodo(todo: Todo) {
this.pItems.splice(this.pItems.indexOf(todo), 1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment