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

Testing Angular services

 

Let's first create a Todo.ts model class that represents the Todo item. The following code snippet shows the content of the Todo class:

export class Todo { 
    title: string; 
    completed: boolean;
    constructor(title: string) { 
        this.title = title; 
        this.completed = false; 
    } 
    set isCompleted(value: boolean) { 
        this.completed = value; 
    } 
} 

 

Next, create a service todo.service.ts that constructs the list of Todo items in the constructor. The complete code of todo.service.ts is as shown:

 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 ...

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