Skip to main content
Version: v1.46.0

Angular SDK

NPM Version NPM Downloads

This page describes how to use the OpenFeature Angular SDK for your client application.

About this provider

OpenFeature Agular SDK allows you to connect to your GO Feature Flag instance with the @openfeature/angular-sdk.

If you work with Angular the @openfeature/angular-sdk will give you a better integration with your Angular application. To integrate it with GO Feature Flag, you need to use the @openfeature/go-feature-flag-web-provider provider.

info

We recommend you to check the OpenFeature Angular SDK Documentation to see all the available directives and how to use them.

Install the provider

npm install @openfeature/go-feature-flag-web-provider
npm install @openfeature/angular-sdk

How to use the provider?

Module

To include the OpenFeature Angular directives in your application, you need to import the OpenFeatureModule and configure it using the forRoot method.

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { OpenFeatureModule } from '@openfeature/angular-sdk';
import { GoFeatureFlagWebProvider } from '@openfeature/go-feature-flag-web-provider';

@NgModule({
declarations: [
// Other components
],
imports: [
CommonModule,
OpenFeatureModule.forRoot({
provider: new GoFeatureFlagWebProvider({
endpoint: 'http://localhost:1031'
}),
})
],
})
export class AppModule {
}

Minimal Example

You don't need to provide all the templates. Here's a minimal example using a boolean feature flag:

If initializing and reconciling are not given, the feature flag value that is returned by the provider will determine what will be rendered.

<div *booleanFeatureFlag="'isFeatureEnabled'; default: true">
This is shown when the feature flag is enabled.
</div>

This example shows content when the feature flag isFeatureEnabled is true with a default value of true. No else, initializing, or reconciling templates are required in this case.

Available directives per types

The OpenFeature SDK provides a set of directives booleanFeatureFlag, numberFeatureFlag, stringFeatureFlag and objectFeatureFlag to get the value of a feature flag. See the OpenFeature Angular SDK Documentation for more details on how to use this directive, including how to use <type>FeatureElse, <type>FeatureInitializing, and <type>FeatureReconciling.

<div
*booleanFeatureFlag="'isFeatureEnabled'; default: true; domain: 'userDomain'; else: booleanFeatureElse; initializing: booleanFeatureInitializing; reconciling: booleanFeatureReconciling">
This is shown when the feature flag is enabled.
</div>
<ng-template #booleanFeatureElse>
This is shown when the feature flag is disabled.
</ng-template>
<ng-template #booleanFeatureInitializing>
This is shown when the feature flag is initializing.
</ng-template>
<ng-template #booleanFeatureReconciling>
This is shown when the feature flag is reconciling.
</ng-template>

Required TargetingKey

GO Feature Flag needs a targetingKey to be set on the evaluation context.
This is used to bucket the users into the correct targeting group for the feature flag evaluation.

Don't forget to set a context with a targetingKey in your application.

await OpenFeature.setContext({
targetingKey: 'user-key',
// ...
});

Advanced usage

You can check the OpenFeature Angular SDK Documentation to see all the available directives and how to use them.

Available options

Check the available options for the provider in the web provider page.

Features status

StatusFeatureDescription
Flags Local CacheThe provider is able to cache the flags, it allow to evaluate the feature flags without waiting for the remote evaluation to be done.
Remote EvaluationThe provider is calling the remote server to evaluate the feature flags.
Tracking Flag EvaluationThe provider is tracking all the evaluations of your feature flags and you can export them using an exporter.
Configuration Change UpdatesThe provider is able to update the configuration based on the configuration, it means that the provider is able to react to any feature flag change on your configuration.
Provider Events ReactionsYou can add an event handler to the provider to react to the provider events.
ImplementedIn-progressNot implemented yet

Contribute to the provider

You can find the source of the provider in the open-feature/js-sdk-contrib repository.