Install with the CLI
Standalone (Angular 17+)
1
Environment file
src/environments/environment.ts:2
LucentService
src/app/lucent.service.ts:3
Inject in AppComponent (manual)
Angular’s DI is lazy. The service won’t start until something injects it.
Add this one line to
src/app/app.component.ts:NgModule (pre‑17)
The setup is identical to Standalone — same environment file, sameLucentService, same one‑line inject in AppComponent. The only difference is
which file you inject from.
Notes
providedIn: "root"alone isn’t enough. Angular tree‑shakes services that are never injected anywhere, so you must referenceLucentServicefrom at least one component constructor.ngOnDestroyflushes any buffered events before the tracker shuts down.- If you already use
APP_INITIALIZERfor bootstrap‑time side effects, you can wireLucentServiceinto it instead of relying onAppComponentconstruction. The CLI doesn’t do this automatically because it requires reading your existing provider configuration.