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

标签 javascript angular typescript angular-httpclient

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

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

此模块声明的“更多”是否正确:

  imports: [HttpClientModule]

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

最佳答案

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

关于javascript - 使用 HttpClient 的模块是否应该在导入中声明 HttpClientModule?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58331231/

相关文章:

javascript - 根据菜单高度更改 anchor 位置

javascript - 单击按钮时随机播放数组

angular - immutable.js 不导出 Map

javascript - 如果用户登录则隐藏元素

jquery - 如何在 TypeScript 中获得 jQuery 自动完成功能?

javascript - 创建主数组的修改属性的新数组

javascript - 系列数据无法触发点击事件 | Highcharts

javascript - Angular 8 : ternary operation for img src attribute?

typescript - 如何为 TypeScript 中类的所有属性赋值?

typescript - 如何分派(dispatch)一个 Action 或一个 ThunkAction(在 TypeScript 中,使用 redux-thunk)?