Calling the PUT action of the Web API to update a Todo item

We just added code to consume the Web API GET action and also added code to POST a new Todo item to the Web API. Now, let's consume the PUT action in the Web API to update an existing Todo item. Follow these steps to do so:

  1. Open todo.service.ts.
  2. Add the putTodo function with the following code snippet to update the existing Todo item by calling the PUT action in the Web API:
     putTodo(todo: Todo) {       var headers = new Headers();        headers.append('Content-Type', 'application/json');        this.http.put('/api/todos/' + todo.id,       JSON.stringify(todo), { headers: headers })             .toPromise()             .then(() => todo)             .catch(this.handleError);      } 

This code defines the header with the JSON content type ...

Get Learning Angular for .NET Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.