blob: e6cbb4f17866c1bf1e1a36351dabcb75329d4884 [file] [log] [blame]
Ittay Stern6f900cc2018-08-29 17:01:32 +03001import {AfterContentChecked, Directive, ElementRef, Input} from '@angular/core';
2import {FeatureFlagService} from "../../service/featureFlag.service";
3import * as _ from 'lodash';
4
5/************************************************************************
6 Feature Flag Directive
7 Example:
8 <div featureFlag [flagName]='"<flag name>"'></div>
9 ************************************************************************/
10@Directive({
11 selector: '[featureFlag]'
12})
13export class BasicFeatureFlagDirective implements AfterContentChecked {
14 @Input() flagName: string;
15 element: ElementRef;
16
17 constructor(el: ElementRef, private _featureToggleService: FeatureFlagService) {
18 this.element = el;
19 }
20
21 ngAfterContentChecked(): void {
22 if (!_.isNil(this.element)) {
23 const isFeatureOn: boolean = this._featureToggleService.isFeatureOn(this.flagName);
24 if(!isFeatureOn){
25 this._featureToggleService.hideElement(this.element)
26 }
27 }
28 }
29}