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:
- Open todo.service.ts.
- 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 ...