December 2017
Beginner
372 pages
10h 32m
English
To implement the HTTP GET request in our service class, we need Angular's HTTP module. To use this module we need to define HTTP as a dependency in our NewsapiService class. As we know, to define a dependency in TypeScript we use a constructor function of the class. Angular then makes sure to pass the instance of that module to the class when we create an instance of the class. The following is the updated code of our NewsapiService class:
import {Injectable} from '@angular/core';import {Http} from '@angular/http';@Injectable()export class NewsapiService{ constructor(private _http:Http){}}
Read now
Unlock full access