Registration
provideNexus(config): EnvironmentProviders
For ApplicationConfig.providers. Runs the initial sync as an application
initializer, opens the live stream, and closes the client when the environment
injector is destroyed.
Built on provideAppInitializer(), which replaced APP_INITIALIZER in Angular
19. The destroy hook is registered before the initial sync is awaited, so an
injector destroyed while the sync is still running still closes the client.
The client belongs to the injector, so two micro-frontends on one page - or two
tests in one process - do not share one, and neither do two server-rendered
requests bootstrapped from the same appConfig: one returned value can register
any number of injectors, and each gets its own client, its own
NEXUS_CLIENT_READY promise and its own teardown.
NexusModule.forRoot(config): ModuleWithProviders
The NgModule form. Identical behaviour; import it once, in the root module.
injectNexus(): NexusClient
The client, from an injection context. Equivalent to inject(NEXUS_CLIENT).
Throws before the application initializer has completed, with a message saying
so.
NEXUS_CLIENT
The injection token, if you prefer inject(NEXUS_CLIENT).
NEXUS_CLIENT_READY
The client as a promise, settling when the registration’s initial sync has
completed. Angular starts every application initializer before awaiting any of
them, so anything that must hold the client during bootstrap - registering an
OpenFeature provider, for example - awaits this instead of injecting
NEXUS_CLIENT directly.
Signals
Every signal reads a revision counter bumped by a single change listener, so a component asking for twenty flags adds no listeners at all. Reading one participates in the cache’s TTL, exactly as the plain getters do.NexusStreamState is one of idle, connecting, connected, reconnecting,
polling.
Reads
Actions
State
Constructing the client directly
environment is { ngZone?, isBrowser? }. provideNexus() fills it from the
injector; nexusEnvironmentFromInjector(injector) does the same for code that
builds the client itself. Without a zone the client runs inline, which is correct
for a zoneless application.
Types and constants
NexusConfig, NexusAngularEnvironment, NexusLogger, NexusLogFields,
NexusStreamObserver, NexusStreamState, NexusChangeListener,
PublicApiKey.
assertPublicKey(key) narrows a string to PublicApiKey, throwing if it is not
a public key - the same check the client applies to apiKey.
NOOP_LOGGER, NOOP_STREAM_OBSERVER, FALLBACK_REASON_MAX_ERRORS,
FALLBACK_REASON_RATE_LIMITED, FALLBACK_REASON_TRANSPORT.
Errors
See Error handling for the full hierarchy.NexusServerError
is now exported, alongside NexusConfigError, NexusResponseTooLargeError and
NexusClosedError.
