💻 Tech
This is a short journal, but NullInjectorError: No provider for _HttpClient!
was resolved when I used module-based approach. I already imported HttpClientModule
(this is for HttpClient
used to call an API) in app.component.ts
, which is a standalone component referenced in app.component.ts
using bootstrapApplication
. With module-based approach, the import not happens at module level (app.module.ts
). For some reason, the error was resolved.
core.mjs:6531 ERROR NullInjectorError: NullInjectorError: No provider for _HttpClient!
at NullInjector.get (core.mjs:1654:27)
at R3Injector.get (core.mjs:3093:33)
at R3Injector.get (core.mjs:3093:33)
at injectInjectorOnly (core.mjs:1100:40)
at Module.ɵɵinject (core.mjs:1106:42)
at Object.DataService_Factory [as factory] (data.service.ts:8:25)
at core.mjs:3219:47
at runInInjectorProfilerContext (core.mjs:866:9)
at R3Injector.hydrate (core.mjs:3218:21)
at R3Injector.get (core.mjs:3082:33)