Search code examples
javascriptangulartypescriptangular-httpclient

Should modules that use HttpClient declare the HttpClientModule in imports?


The SVGViewer component in the Angular Material documentation app declares its module like this:

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

Is it "More" correct for this module to declare:

  imports: [HttpClientModule]

Since it uses HttpClient ? IIUC in general modules should declare their dependencies.


Solution

  • No. Because it is imported into a module that already imports the HttpClientModule, the dependency injector knows about the HttpClientModule already. See (https://github.com/angular/material.angular.io/blob/051363fff1f993dd77f70ea9ebf917fbc3f99426/src/app/app-module.ts)