I'm developing a Angular library. I've setup the library like this:
ng new mylibrary --create-application false
ng g library mylib
Now, I can ng build
this and create an app that uses it, like this:
ng new myapp
npm install ../mylibrary/dist/mylib
and add the MylibModule
to the imports
of my app.module.ts
This works fine, by default the library has a component that I can use. There also is a dependency injected service in the library.. also works fine.
Now I want to extend my library with http calls, so I add the HttpClientModule
to the import of my library module, and the HttpClient to the constructor of my service. I rebuild the lib with ng build
and on the app I re-run npm install
.. and run with ng serve
and now my app throws:
StaticInjectorError(Platform: core)[HttpHandler -> Injector]:
NullInjectorError: No provider for Injector!
I guess I somehow have to tell the library to use the injected HttpClient from the app, but how?
EDIT Adding repo: https://github.com/floreseken/NgLibDI