Angular
schematic-angular is a client-side Angular library for Schematic which provides an injectable service to track events, check flags, and more. schematic-angular provides the same capabilities as schematic-js, for Angular apps.
Install
Usage
Setup with provideSchematic
Add provideSchematic to your application’s providers. This works with both standalone and NgModule-based apps.
Standalone app (app.config.ts):
NgModule-based app:
You can also pass a pre-configured client:
Setting context
To set the user context for events and flag checks, use the identify method on SchematicService:
To learn more about identifying companies with the keys map, see key management in Schematic public docs.
Tracking usage
Once you’ve set the context with identify, you can track events:
If you want to record large numbers of the same event at once, or measure usage in terms of a unit like tokens or memory, you can optionally specify a quantity:
Checking flags
Use flagValue$ to get an Observable of a flag’s boolean value:
With async pipe:
With Signals (Angular 16+):
Checking entitlements
Use entitlement$ to get an Observable with detailed entitlement data including usage information:
Note: isPending$ checks if entitlement data has been loaded, typically via identify. It should be used to wrap flag and entitlement checks, but never the initial call to identify.
Checking plans
Use plan$ to get an Observable of the current plan information:
API Reference
provideSchematic(config)
Configures the Schematic client for dependency injection. Accepts either a publishableKey string or a pre-configured client instance, plus any SchematicOptions.
SchematicService
Injectable service providing all Schematic functionality:
SCHEMATIC_CLIENT
InjectionToken<Schematic> for direct access to the raw client instance via Angular DI.
Fallback Behavior
The SDK includes built-in fallback behavior to ensure your application continues to function even when unable to reach Schematic.
Flag Check Fallbacks
When flag checks cannot reach Schematic, they use fallback values in the following priority order:
- Callsite fallback: provided as the second argument to
flagValue$orentitlement$ - Initialization defaults: configured via
flagCheckDefaultsorflagValueDefaultsoptions inprovideSchematic - Default value: returns
falseif no fallback is configured
Event Queueing and Retry
When events (track, identify) cannot be sent due to network issues, they are automatically queued and retried:
- Events are queued in memory (up to 100 events by default, configurable via
maxEventQueueSize) - Failed events are retried with exponential backoff (up to 5 attempts by default, configurable via
maxEventRetries) - Events are automatically flushed when the network connection is restored
WebSocket Fallback
In WebSocket mode, if the WebSocket connection fails, the SDK will provide the last known value or the configured fallback values as outlined above. The WebSocket will also automatically attempt to re-establish its connection using an exponential backoff.
Troubleshooting
For debugging and development, Schematic supports two special modes:
Debug Mode
Enables console logging of all Schematic operations:
Offline Mode
Prevents network requests and returns fallback values for all flag checks:
Offline mode automatically enables debug mode to help with troubleshooting.
License
MIT
Support
Need help? Please open a GitHub issue or reach out to support@schematichq.com and we’ll be happy to assist.