使用 HttpClient 的模块是否应该在导入中声明 HttpClientModule?

Should modules that use HttpClient declare the HttpClientModule in imports?

The SVGViewer component 在 Angular Material 文档应用程序中声明其模块如下:

@NgModule({
  exports: [SvgViewer],
  declarations: [SvgViewer],
})

这个模块声明"More"是否正确:

  imports: [HttpClientModule]

因为它使用 HttpClient ? IIUC 在一般模块中应该声明它们的依赖关系。

没有。因为它被导入到一个已经导入了 HttpClientModule 的模块中,所以依赖注入器已经知道 HttpClientModule。参见 (https://github.com/angular/material.angular.io/blob/051363fff1f993dd77f70ea9ebf917fbc3f99426/src/app/app-module.ts)