summaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/src/app/featureFlag/service/featureFlag.service.ts
blob: 09ce7bbf5974e60c7a88e8c18b74ec1c92e7622b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import {ElementRef, Injectable, Renderer2, RendererFactory2} from "@angular/core";
import {ConfigurationService} from "../../shared/services/configuration.service";

@Injectable()
export class FeatureFlagService{
  private features :  { [key: string]: boolean } = {};
  private renderer: Renderer2;
  constructor(private _configurationService: ConfigurationService,
              rendererFactory: RendererFactory2){
    this.renderer = rendererFactory.createRenderer(null, null);
    this._configurationService.getFlags().subscribe((res: { [key: string]: boolean }) =>{
      this.features = res;
    })
  }


  isFeatureOn(feature : string) : boolean {
    return this.features && this.getFeatureFlag()[feature] === true;
  }

  getFeatureFlag() : { [key: string]: boolean } {
    return this.features;
  }

  hideElement(element: ElementRef) {
    this.renderer.setStyle(element.nativeElement, 'display', 'none');
  }
}