ngx-highlightjs
ngx-highlightjs copied to clipboard
Usage in Angular module: Error: inject() must be called from an injection context
Reproduction
Steps to reproduce:
- Use
ngx-hightlightjs
in a component which is exported through an Angular module - Use the exported component in an Angular app
Expected Behavior
We want to use ngx-highlightjs
in one of our Angular modules but are not able to do so. We tried different variants:
Importing the HighlightModule
just in the Library Module or Importing and Exporting the HighlightModule
from the Library Module. We set the provider from within the Angular app.
The library project which imports the HighlightModule compiles fine. So does the angular project which imports our library module. When opening the browser, we need the HighlightModule to work inside a Component created and exported from the Library Module for usage in our Anguar app project.
Actual Behavior
When opening the GUI which uses the component exported by our library module which relies on the on the [code]
directive, the browser console logs the following error:
Error: inject() must be called from an injection context
at injectInjectorOnly (core.js:4764:1)
at ɵɵinject (core.js:4774:1)
at Module.ɵɵdirectiveInject (core.js:14753:1)
at NodeInjectorFactory.Highlight_Factory [as factory] (ngx-highlightjs.mjs:353:1)
at getNodeInjectable (core.js:3561:1)
at instantiateAllDirectives (core.js:10298:1)
at createDirectivesInstances (core.js:9647:1)
at ɵɵelementStart (core.js:14900:1)
at Module.ɵɵelement (core.js:14951:1)
at DashboardButtonComponent_Template (dashboard-button.component.html:7:47)
Environment
- Angular: 12.2.16
- ngx-highlightjs: 6.1.3
- Browser(s): Chrome, Safari
- Operating System (e.g. Windows, macOS, Ubuntu): macOS
It is difficult to guess without reproduction, but I would guess something is wrong with HIGHLIGHT_OPTIONS
, try to provide it in the root module