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/' +,       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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.