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

Consuming Web API GET Action in TodoService

First, let's update the TodoService that consumes Web API service to fetch a list of Todo items. We will use the Http service to communicate with Web API service:

  1. Open the todoService.ts file in an app folder.
  2. Add the following import statements to import modules such as Injectable, Http, headers, Response, Observable, map, and Todo:
   import { Injectable } from '@angular/core';    import { Http, Headers } from '@angular/http';    import 'rxjs/add/operator/toPromise';   import { Todo } from './todo'
  1. Modify constructor to inject the Http service by adding the parameter for the Http service:
  constructor (private http: Http) { ... } 
  1. Add the getTodos method to consume the Web API service to get the ...

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