Guest User

Untitled

a guest
Mar 18th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. import { Directive, Input, TemplateRef, ViewContainerRef, OnInit } from '@angular/core';
  2. import { CONFIG } from 'environments/config';
  3.  
  4. @Directive({
  5. selector: '[featureToggle]'
  6. })
  7. export class FeatureToggleDirective implements OnInit {
  8. @Input() featureToggle: string;
  9.  
  10. constructor(
  11. private templateRef: TemplateRef<any>,
  12. private viewContainer: ViewContainerRef
  13. ) {}
  14.  
  15. ngOnInit() {
  16. if (this.isEnabled()) {
  17. this.viewContainer.createEmbeddedView(this.templateRef);
  18. } else {
  19. this.viewContainer.clear();
  20. }
  21. }
  22.  
  23. isEnabled() {
  24. const { features } = CONFIG;
  25. if (features['*']) {
  26. return true;
  27. }
  28.  
  29. return features[this.featureToggle];
  30. }
  31. }
Add Comment
Please, Sign In to add comment