Skip to main content
Scaffold + manual step. The CLI writes the environment file and LucentService, but Angular’s DI is lazy — the service won’t run until something injects it. You must add a one‑line constructor inject in AppComponent after the CLI finishes.

Install with the CLI

Pick Angular when prompted, then choose your style.

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, same LucentService, 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 reference LucentService from at least one component constructor.
  • ngOnDestroy flushes any buffered events before the tracker shuts down.
  • If you already use APP_INITIALIZER for bootstrap‑time side effects, you can wire LucentService into it instead of relying on AppComponent construction. The CLI doesn’t do this automatically because it requires reading your existing provider configuration.