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

Updating a model in an Angular app

First, we need to add the id property to Todo.ts in an Angular app to hold the ID of the Todo item received from the API. So, the updated Todo.ts will look as follows:

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

The constructor takes three arguments: id, title, and completed, and assigns them to the id, title, and completed properties respectively, accessing them using the this keyword. The Todo class also sets an accessor for the completed property.

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