File

projects/core/src/features-config/directives/feature.directive.ts

Metadata

Selector [cxFeature]

Index

Properties
Inputs
Accessors

Constructor

constructor(templateRef: TemplateRef, viewContainer: ViewContainerRef, featureConfig: FeatureConfigService)
Parameters :
Name Type Optional
templateRef TemplateRef<any> No
viewContainer ViewContainerRef No
featureConfig FeatureConfigService No

Inputs

cxFeature
Type : string

Properties

Private hasView
Default value : false

Accessors

cxFeature
setcxFeature(feature: string)
Parameters :
Name Type Optional
feature string No
Returns : void
import { Directive, Input, TemplateRef, ViewContainerRef } from '@angular/core';
import { FeatureConfigService } from '../services/feature-config.service';

@Directive({
  selector: '[cxFeature]',
})
export class FeatureDirective {
  constructor(
    protected templateRef: TemplateRef<any>,
    protected viewContainer: ViewContainerRef,
    protected featureConfig: FeatureConfigService
  ) {}

  private hasView = false;

  @Input() set cxFeature(feature: string) {
    if (this.featureConfig.isEnabled(feature) && !this.hasView) {
      this.viewContainer.createEmbeddedView(this.templateRef);
      this.hasView = true;
    } else if (!this.featureConfig.isEnabled(feature) && this.hasView) {
      this.viewContainer.clear();
      this.hasView = false;
    }
  }
}

result-matching ""

    No results matching ""