Last active
November 9, 2017 15:55
-
-
Save orlando-c-h/e8c95bed68354eec6f96472a83be7d34 to your computer and use it in GitHub Desktop.
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 { 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