DEV Community

Lukasz Kuklis
Lukasz Kuklis

Posted on

Hide on prod - Angular Directive

*hideOnProd directive

import { Directive, ViewContainerRef, OnInit, TemplateRef } from '@angular/core';
import { environment } from 'path/to/environments/environment';

@Directive({
  selector: '[hideOnProd]'
})
export class HideOnProdDirective implements OnInit{

  constructor(private templateRef: TemplateRef<any>, private viewContainerRef: ViewContainerRef) { }

  ngOnInit(): void {
     if(environment.production == false){
      this.viewContainerRef.createEmbeddedView(this.templateRef);
    }
  }

}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)