- Angular 6 for Enterprise:Ready Web Applications
- Doguhan Uluca
- 173字
- 2021-06-25 21:20:33
Inject dependencies
In order to make API calls, you will be leveraging the HttpClient module in Angular. The official documentation (https://angular.io/guide/http) explains the benefits of this module succinctly:
"With HttpClient, @angular/common/http provides a simplified API for HTTP functionality for use with Angular applications, building on top of the XMLHttpRequest interface exposed by browsers. Additional benefits of HttpClient include testability support, strong typing of request and response objects, request and response interceptor support, and better error handling via APIs based on Observables."
Let's start with importing the HttpClientModule in to our app, so we can inject the HttpClient within the module into the WeatherService:
- Add HttpClientModule to app.module.ts, as follows:
src/app/app.module.ts ... import { HttpClientModule } from '@angular/common/http' ... @NgModule({ ... imports: [ ... HttpClientModule, ...
- Inject HttpClient provided by the HttpClientModule in the WeatherService, as follows:
src/app/weather/weather.service.ts
import { HttpClient } from '@angular/common/http'
import { Injectable } from '@angular/core'
@Injectable()
export class WeatherService {
constructor(private httpClient: HttpClient) {}
}
Now, httpClient is ready for use in your service.
- 網絡云百問百答
- 物聯網短距離無線通信技術應用與開發
- OpenLayers Cookbook
- 新一代物聯網架構技術:分層算力網絡
- Windows Server 2003 Active Directory Design and Implementation: Creating, Migrating, and Merging Networks
- PLC、現場總線及工業網絡實用技術速成
- Practical Web Design
- 物聯網通信技術
- Building RESTful Web services with Go
- 網絡環境中基于用戶視角的信息質量評價研究
- 網絡安全應急響應技術實戰指南
- VMware NSX網絡虛擬化入門
- 通信十年:擁抱互聯網
- Learning Node.js Development
- 物聯網概論