Angular 4、httpClient和HttpClientModule的区别

Angular 4, difference between httpClient and HttpClientModule

在本文 here 和其他文章中:看起来您需要在 app.module.ts 中导入 HttpClientModule 并在 app.component.ts 中导入 HttpClient 才能发出 http 请求。为什么?它们是如何工作的?

简单来说,

您可以将 HttpClientModule 作为 "feature-bundle" 调用,作为 Angular 中的核心部分。在这个 "feature-bundle" 中,您还有许多其他小功能,例如 HttpClient(在 Angular 语言中,它是 "service")、拦截器等

为了使用这些 "feature(s)",您需要在主模块中导入 "feature-bundle"(在您的例子中,Angular 的 AppModule),这样,您可以访问工作组件中的 HttpClient 和许多其他服务。

一个班轮:

HttpClient is a angular service bundled inside HttpClientModule.