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)

Let's Get Hacking

Join the DEV x Linode Hackathon 2022 and use your ingenuity and creativity to build using Linode.

Join the Hackathon <-