Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 1 | import {ElementRef, Injectable, Renderer2, RendererFactory2} from "@angular/core"; |
| 2 | import {ConfigurationService} from "../../shared/services/configuration.service"; |
| 3 | |
| 4 | @Injectable() |
| 5 | export class FeatureFlagService{ |
| 6 | private features : { [key: string]: boolean } = {}; |
| 7 | private renderer: Renderer2; |
| 8 | constructor(private _configurationService: ConfigurationService, |
| 9 | rendererFactory: RendererFactory2){ |
| 10 | this.renderer = rendererFactory.createRenderer(null, null); |
| 11 | this._configurationService.getFlags().subscribe((res: { [key: string]: boolean }) =>{ |
| 12 | this.features = res; |
| 13 | }) |
| 14 | } |
| 15 | |
| 16 | |
| 17 | isFeatureOn(feature : string) : boolean { |
| 18 | return this.features && this.getFeatureFlag()[feature] === true; |
| 19 | } |
| 20 | |
| 21 | getFeatureFlag() : { [key: string]: boolean } { |
| 22 | return this.features; |
| 23 | } |
| 24 | |
| 25 | hideElement(element: ElementRef) { |
| 26 | this.renderer.setStyle(element.nativeElement, 'display', 'none'); |
| 27 | } |
| 28 | } |