Forked from faisalmuhammad/development-only.directive.ts
Created
June 4, 2018 13:18
-
-
Save robertdean/5d5e26912e238fdafbd827d0c1c97002 to your computer and use it in GitHub Desktop.
Angular | Development Only Directive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @author Muhammad FAISAL | |
* @description Controls the display of html contents only during development mode. | |
* @example <button development-only>Some Button</button> | |
*/ | |
// Angular Imports | |
import { Directive, OnInit, ElementRef, isDevMode } from '@angular/core'; | |
// Define class for the Directive | |
@Directive({ | |
selector: '[development-only]' | |
}) | |
export class DevelopmentOnlyDirective implements OnInit { | |
/** | |
* Initializes an instance of DevelopmentOnlyDirective class. | |
* @param _elementRef Reference to the element where this directive is applied. | |
*/ | |
constructor(private readonly _elementRef: ElementRef) { } | |
/** | |
* Invoked when component initializes. | |
*/ | |
ngOnInit() { | |
const isDevelopment = isDevMode(); | |
if (!isDevelopment && this._elementRef.nativeElement.parentNode !== null) { | |
this._elementRef.nativeElement.outerHTML = ''; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment