Hide on prod - Angular Directive

lkuklis

Lukasz Kuklis

Posted on December 25, 2021

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
💖 đŸ’Ș 🙅 đŸš©
lkuklis
Lukasz Kuklis

Posted on December 25, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Angular Form Array
angular Angular Form Array

November 29, 2024

Can a Solo Developer Build a SaaS App?
undefined Can a Solo Developer Build a SaaS App?

November 29, 2024

Angular's New Feature: Signals
javascript Angular's New Feature: Signals

November 29, 2024