diff --git a/packages/angular/projects/angular-sdk/src/lib/feature-flag.directive.ts b/packages/angular/projects/angular-sdk/src/lib/feature-flag.directive.ts index c44761155..dd8e30d02 100644 --- a/packages/angular/projects/angular-sdk/src/lib/feature-flag.directive.ts +++ b/packages/angular/projects/angular-sdk/src/lib/feature-flag.directive.ts @@ -5,6 +5,7 @@ import { Input, OnChanges, OnDestroy, + OnInit, TemplateRef, ViewContainerRef, } from '@angular/core'; @@ -33,7 +34,7 @@ class FeatureFlagDirectiveContext { standalone: true, selector: '[featureFlag]', }) -export abstract class FeatureFlagDirective implements OnDestroy, OnChanges { +export abstract class FeatureFlagDirective implements OnInit, OnDestroy, OnChanges { protected _featureFlagDefault: T; protected _featureFlagDomain: string | undefined; @@ -69,14 +70,21 @@ export abstract class FeatureFlagDirective implements OnDes templateRef: TemplateRef>, ) { this._thenTemplateRef = templateRef; - this.initClient(); } set featureFlagDomain(domain: string | undefined) { + /** + * We have to handle the change of the domain explicitly because we need to get a new client when the domain changes. + * This can not be done if we simply relay the onChanges method. + */ this._featureFlagDomain = domain; this.initClient(); } + ngOnInit(): void { + this.initClient(); + } + ngOnChanges(): void { this._flagChangeHandler?.(); } @@ -200,7 +208,7 @@ export abstract class FeatureFlagDirective implements OnDes * Usage examples: * * ``` - *
{{ value }}
+ *
{{ value }}
* ``` * ``` *
Content to render when flag is true.