O'Reilly logo

Learning Angular for .NET Developers by Rajesh Gunasundaram

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding a TodoService class

Now, let's create a TodoService class that acts as a service repository to manage todo items. The following is the code snippet of the todo.service.ts file:

import { Todo } from './todo'    export class TodoService {       todos: Array<Todo>       constructor() {           this.todos = [new Todo('First   item'),           new Todo('Second item'),           new Todo('Third item')];       }       getPending() {           return   this.todos.filter((todo: Todo) => todo.completed ===         false);       }       getCompleted() {           return   this.todos.filter((todo: Todo) => todo.completed ===         true);       }       remove(todo: Todo) {             this.todos.splice(this.todos.indexOf(todo), 1);       }          add(title: string) {           this.todos.push(new   Todo(title));       }       toggleCompletion(todo: Todo)   {    todo.completed = !todo.completed; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required