Quickstart by stack
Angular Quickstart
Install the Angular SDK, provide Zenmanage in your app, and read flags with signals, structural directives, and route guards, in standalone, NgModule, and Angular SSR apps.
Prerequisites
- Angular 20 or newer, RxJS 7.8 or newer, and @zenmanage/sdk 3.5.1 or newer.
- A client key (prefixed cli_) in your build configuration for the browser. Server rendering needs a server key (prefixed srv_) from a server-only environment variable. Mobile keys are not valid for this package.
- A flag key you can test in a non-production environment.
npm install @zenmanage/angular @zenmanage/sdk
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' }),
],
};
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');
}
Safe defaults, explicit loading
Every inject function takes a default and returns it until the flag resolves, and again if evaluation fails. isLoading() and error() are signals, so you decide what the UI does in each state. The type of the default decides how the flag is read: boolean, string, number, or JSON. If the API is unreachable, you get your defaults.
Built on the JavaScript SDK
The package is a thin wrapper around @zenmanage/sdk, so caching, context handling, and defaults behave the same way they do in the JavaScript quickstart. Pass your own client to provideZenmanage if you already have one.
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 {}
import { ZenmanageModule } from '@zenmanage/angular';
@NgModule({
imports: [
BrowserModule,
// Also exports *zenmanageIfFlag and *zenmanageIfVariant
ZenmanageModule.forRoot({ environmentToken: 'cli_your_client_key_here' }),
],
})
export class AppModule {}
import { signal } from '@angular/core';
import { Attribute, Context } from '@zenmanage/sdk';
import { injectFlag, provideZenmanage } from '@zenmanage/angular';
export const currentUser = signal<Context | undefined>(undefined);
provideZenmanage({ environmentToken: 'cli_your_client_key_here', context: currentUser });
// When someone signs in, every flag on screen re-evaluates.
const context = Context.single('user', user.id);
context.addAttribute(new Attribute('plan', [user.plan]));
currentUser.set(context);
// Inside a component, the key can change too.
const section = signal('billing');
const limit = injectFlag(() => `${section()}-limit`, 100);
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 {}
const timeout = injectConfig('api-timeout-ms', 5000);
const copy = injectConfig('hero-copy', 'Welcome');
const ui = injectFlag('ui-config', { theme: 'light', pageSize: 20 });
const steps = injectFlag<string[]>('onboarding-steps', []);
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),
},
];
import { inject } from '@angular/core';
import { ZenmanageFlagsService } from '@zenmanage/angular';
const flags = inject(ZenmanageFlagsService);
const enabled = await flags.isEnabled('new-dashboard', false);
const variant = await flags.getVariant('checkout-flow', 'control');
const { value } = await flags.getValue('ui-config', { theme: 'light' });
Client keys only in the browser
Use a cli_ key in the browser. A srv_ key throws there, and a cli_ key throws in Node.js. Never ship a server key to the browser — read it from a server-only environment variable.
Server-side rendering
With Angular SSR, the server evaluates flags while it renders and waits for them, so the HTML carries the real values. The server hands the flags the page read to the browser through TransferState, so the first browser render matches the server HTML and the default never flashes. It works with and without zone.js. The server shares one client between requests and caches rules for 60 seconds unless you set cacheTtl.
import type { ApplicationConfig } from '@angular/core';
import { provideZenmanage } from '@zenmanage/angular';
export const appConfig: ApplicationConfig = {
providers: [provideZenmanage({ environmentToken: 'cli_your_client_key_here' })],
};
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);
import { getBootstrapPayload, getFlagValue } from '@zenmanage/angular';
// An API route or middleware on the server
const enabled = await getFlagValue({ environmentToken, key: 'new-checkout', context }, false);
// Every flag in the environment, or just the ones you name
const payload = await getBootstrapPayload({ environmentToken, context, keys: ['new-checkout'] });
Next step
Take the next integration step in your own stack.
Start with the quickstart that matches your runtime, then return to the reference pages when you need exact request and payload details.
Language and framework names and logos shown above are trademarks or registered trademarks of their respective owners. Their use here is for identification purposes only and does not imply endorsement of, or affiliation with, Zenmanage.