Introducing the Zenmanage Angular SDK
The Zenmanage Angular SDK adds signals, structural directives, route guards, and a flags service to your Angular app, in standalone and NgModule setups, with server rendering that doesn't flash the default.
@zenmanage/angular. Provide it once, read flags as signals with injectFlag, gate templates with *zenmanageIfFlag, gate routes with a guard, and render flags on the server in Angular SSR so the browser starts from the same values.
Angular apps live a long time. The one you're working in probably started on NgModules, picked up standalone components halfway through, and has at least one service that was written before signals existed. A feature flag layer has to fit all of that. Most hand-rolled ones don't: an APP_INITIALIZER that blocks bootstrap on a network call, a BehaviorSubject nobody remembers to unsubscribe from, an *ngIf that renders the old UI for a beat before the real answer arrives.
Add server rendering and it gets worse. The server renders with the default, the browser loads the real value, and the page swaps. The Angular SDK is that wiring, written once: signals for the template, a service for code, directives and guards for the places flags usually end up, and the server case handled.
What it is
@zenmanage/angular is a thin layer over the Zenmanage JavaScript SDK, the same way the React and Vue SDKs are. It doesn't reimplement evaluation, caching, or targeting, so a flag behaves the same in your components as it does in the JavaScript quickstart. What it adds is the Angular-shaped part: a provider function, four inject functions that return signals, two structural directives, route guards, and a service.
It needs Angular 20 or newer, RxJS 7.8 or newer, and @zenmanage/sdk 3.5.1 or newer. We left Angular 17 to 19 out on purpose, because they're out of support.
Getting started
Install the package from npm. @zenmanage/sdk is a peer dependency, so list it alongside:
npm install @zenmanage/angular @zenmanage/sdk
In a standalone application, add provideZenmanage to your application config with a client key. In the browser that's a key prefixed cli_, read from your build configuration:
import type { ApplicationConfig } from '@angular/core';
import { provideRouter } from '@angular/router';
import { provideZenmanage } from '@zenmanage/angular';
import { routes } from './app.routes';
export const appConfig: ApplicationConfig = {
providers: [
provideRouter(routes),
provideZenmanage({ environmentToken: 'cli_your_client_key_here' }),
],
};
The first load starts with the application and doesn't block bootstrap, so by the time a component asks for a flag the rules are usually already in memory. Now read a flag in a component:
import { Component } from '@angular/core';
import { injectBooleanFlag } from '@zenmanage/angular';
@Component({
selector: 'app-checkout-button',
template: `
@if (newCheckout.isLoading()) {
<button disabled>Loading...</button>
} @else {
<button>{{ newCheckout.value() ? 'Checkout (new)' : 'Checkout' }}</button>
}
`,
})
export class CheckoutButtonComponent {
readonly newCheckout = injectBooleanFlag('new-checkout-button');
}
injectBooleanFlag is a field initializer, so it runs in an injection context, and what it returns is a set of signals: value(), isLoading(), and error(). injectFlag(key, default) is the general version, and the type of the default decides how the flag is read. Pass a boolean and you get a boolean, a string and you get a string, an object or an array and you get a JSON flag. The default is also what you get until the flag resolves, and again if the API can't be reached, so pick one that's safe to run with.
Standalone components and NgModules
You don't have to finish a migration before you adopt this. A standalone component imports the directive it uses, and an NgModule application imports ZenmanageModule, which provides the service and exports both directives to every component the module declares:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ZenmanageModule } from '@zenmanage/angular';
@NgModule({
imports: [
BrowserModule,
ZenmanageModule.forRoot({ environmentToken: 'cli_your_client_key_here' }),
],
})
export class AppModule {}
Both routes configure the same service, and the inject functions, the service, and the guards work the same way in either. That matters in a large application where one team's feature module is standalone and another's isn't: they read from the same flags, on the same loaded rules, with one client. It also means the day you convert a module to standalone, the flag code doesn't change.
Conditional rendering with structural directives
When the decision is about what the template renders, say so in the template. *zenmanageIfFlag takes the flag key, with optional else and loading templates:
import { Component } from '@angular/core';
import { ZenmanageIfFlagDirective } from '@zenmanage/angular';
@Component({
selector: 'app-dashboard',
// A standalone component imports the directive it uses.
imports: [ZenmanageIfFlagDirective, DashboardV1Component, DashboardV2Component],
template: `
<app-dashboard-v2 *zenmanageIfFlag="'new-dashboard'; else: legacy; loading: spinner" />
<ng-template #legacy><app-dashboard-v1 /></ng-template>
<ng-template #spinner><p>Loading...</p></ng-template>
`,
})
export class DashboardComponent {}
With no loading template, nothing renders until the first value arrives. A background refresh doesn't tear the view down and rebuild it unless the answer actually changes, so a refresh that returns the same answer leaves the screen alone.
*zenmanageIfVariant is the same idea for A/B tests. A string flag can carry more than on and off, and is takes one variant or a list. The control experience is what anyone sees if the flag can't be read:
import { Component } from '@angular/core';
import { ZenmanageIfVariantDirective } from '@zenmanage/angular';
@Component({
selector: 'app-checkout-page',
imports: [ZenmanageIfVariantDirective, CheckoutComponent, ClassicCheckoutComponent],
template: `
<app-checkout *zenmanageIfVariant="'checkout-flow'; is: ['one-page', 'stepper']; else: control" />
<ng-template #control><app-classic-checkout /></ng-template>
`,
})
export class CheckoutPageComponent {}
Which users land in which variant is decided in Zenmanage, through targeting rules and percentage rollouts, not in your component. Changing the split doesn't mean shipping a new build.
The service, for code that isn't a template
Plenty of flag decisions don't live in a template. They live in a facade, an interceptor, or a state service. ZenmanageFlagsService is the injectable for that. It evaluates against the same rules and waits for the first load, so a call reads from a warm cache:
import { Injectable, inject } from '@angular/core';
import { ZenmanageFlagsService } from '@zenmanage/angular';
@Injectable({ providedIn: 'root' })
export class CheckoutFacade {
private readonly flags = inject(ZenmanageFlagsService);
async checkoutPath(): Promise<string> {
const onePage = await this.flags.isEnabled('one-page-checkout', false);
return onePage ? '/checkout/one-page' : '/checkout';
}
checkoutVariant(): Promise<string> {
return this.flags.getVariant('checkout-flow', 'control');
}
}
The service also exposes its state, isReady, isLoading, and error, as both signals and observables, so you can use whichever your component already speaks: a signal in a template, or an observable behind an async pipe. If the rules can't be loaded, the service settles on your defaults instead of hanging, sets error, and calls the onError handler you pass to provideZenmanage. If you already have a configured Zenmanage client, hand it to provideZenmanage as client and the package uses it as is.
Gating routes
A flag often decides whether a whole page exists. canActivateFlag and canMatchFlag are functional guards that wait for the flags to load. canMatchFlag is the more useful one in a lazy-loaded app: a disabled flag makes the route not match at all, so the router falls through to the next route with the same path and never downloads the new chunk:
import type { Routes } from '@angular/router';
import { canActivateFlag, canMatchFlag } from '@zenmanage/angular';
export const routes: Routes = [
{
path: 'beta',
canActivate: [canActivateFlag({ key: 'beta-program', redirectTo: '/upgrade' })],
loadComponent: () => import('./beta.component').then((m) => m.BetaComponent),
},
{
// A disabled flag skips this route, so the next 'dashboard' route matches.
path: 'dashboard',
canMatch: [canMatchFlag({ key: 'dashboard-v2' })],
loadComponent: () => import('./dashboard-v2.component').then((m) => m.DashboardV2Component),
},
{
path: 'dashboard',
loadComponent: () => import('./dashboard.component').then((m) => m.DashboardComponent),
},
];
Guards can also match a variant instead of a boolean with expectedVariant, and redirectTo takes a URL or a UrlTree. If your routes are configured from data, ZenmanageFlagGuard reads the same options from data.zenmanageFlag.
Keys, context, and defaults can be signals
The user signs in, the route changes, an input updates. A flag read shouldn't need tearing down and rebuilding each time. Pass a signal or a function and the SDK tracks it. This one holds the evaluation context for whoever is signed in, and every flag on screen re-evaluates when it changes:
import { signal } from '@angular/core';
import { Attribute, Context } from '@zenmanage/sdk';
import { provideZenmanage } from '@zenmanage/angular';
export const currentUser = signal<Context | undefined>(undefined);
export const zenmanageProvider = provideZenmanage({
environmentToken: 'cli_your_client_key_here',
context: currentUser,
});
// When someone signs in:
export function onSignIn(user: { id: string; plan: string }): void {
const context = Context.single('user', user.id);
context.addAttribute(new Attribute('plan', [user.plan]));
currentUser.set(context);
}
Setting it back to undefined on sign-out means no context. While new values load, the signals report isLoading again, so a template shows its loading state instead of the previous user's answer. The context is compared by content, so a new object that's equal to the old one doesn't restart anything. A flag key works the same way: injectFlag(() => `${section()}-limit`, 100) re-evaluates when section changes.
The context decides who a flag is evaluated for, and a percentage rollout buckets by the context's identifier, so use one that stays the same for a user across sessions.
Angular SSR, without the flash
On the server, the inject functions and directives evaluate flags while Angular renders, and each evaluation holds a PendingTask, so the server waits for the flags before it serializes the page. The HTML that leaves your server already carries the real values. Then the browser has to start from the same ones, or hydration complains. Here's the sequence:
- The server renders your page and evaluates every flag the page reads, using a server key.
- When the page is serialized, the service writes those flags into
TransferState, so they travel in theng-statescript tag with the rest of Angular's transferred state. - The browser's service reads that payload, so its first render matches the server HTML. No mismatch, no flash of the default.
- The browser loads its own rules, and its live value replaces the server's when they arrive. If they never arrive, because of a blocked CDN or no network, the server's value stays.
You'll use two keys, and they never swap places. Keep them in two config files so the server key stays out of the browser bundle. The server config is merged after the browser's, so its provider wins:
// app.config.ts (browser)
import type { ApplicationConfig } from '@angular/core';
import { provideZenmanage } from '@zenmanage/angular';
export const appConfig: ApplicationConfig = {
providers: [provideZenmanage({ environmentToken: 'cli_your_client_key_here' })],
};
// app.config.server.ts (server)
import { mergeApplicationConfig, type ApplicationConfig } from '@angular/core';
import { provideServerRendering } from '@angular/platform-server';
import { provideZenmanage } from '@zenmanage/angular';
import { appConfig } from './app.config';
const serverConfig: ApplicationConfig = {
providers: [
provideServerRendering(),
// A server key from a server-only environment variable replaces the browser's client key.
provideZenmanage({ environmentToken: process.env['ZENMANAGE_SERVER_KEY'] ?? '' }),
],
};
export const config = mergeApplicationConfig(appConfig, serverConfig);
That's all of it. After that, injectFlag, the directives, and the guards work in any component as they do in a browser-only app, with no server-only branch in your components. It works with and without zone.js. On the server, the package shares one client between requests and caches rules for 60 seconds unless you set cacheTtl, so one request reuses the rules the one before it fetched. For server code that isn't a component, such as an API route or middleware, getFlagValue and getBootstrapPayload read flags the same way. The SSR guide in the repository covers those and the context options.
Three things to know before you ship
The server key stays on the server
@zenmanage/sdk checks the key against where it's running. A srv_ key throws in a browser and a cli_ key throws in Node.js, and mobile keys (mob_) aren't valid for this package. That's deliberate: a server key in a browser bundle is a leaked secret. Read client keys from build-time configuration and keep server keys in server-only environment variables.
The transferred state is public
ng-state is written into the page, so anyone who views the source can read it. It holds only the flags your page actually read through injectFlag and the directives, with their values. The context is left out by default because a context can carry personal data; build it again in the browser from the session, or opt in with transferContext once you've checked what's in it. A flag read only by a route guard or a service call isn't in the payload, so the browser evaluates it itself.
Angular 20 or newer
Peer dependencies cover Angular 20, 21, and 22. If you're on an older version, the JavaScript SDK runs in any browser app, Angular or not. You'd write the service and the loading states yourself, which is the work this package exists to save you.
What's next
@zenmanage/angular 1.0.0 is on npm now. The source is on GitHub, with runnable examples, a standalone application with routing, guards, and SSR, and a smoke-test app we build against Angular 20, 21, and 22. The Angular quickstart walks through setup end to end, and the SDK overview lists every language we support.
If something in the package gets in your way, tell us at hello@zenmanage.com or open an issue on GitHub.