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

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

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