File

src/app/directives/hide.directive.ts

Implements

OnChanges

Metadata

Index

Methods
Inputs

Constructor

constructor(renderer: Renderer2, elRef: ElementRef)
Parameters :
Name Type Optional
renderer Renderer2 No
elRef ElementRef No

Inputs

hide
Type : boolean

Methods

ngOnChanges
ngOnChanges()
Returns : void
import {
  Directive,
  ElementRef,
  Input,
  OnChanges,
  Renderer2
} from '@angular/core';

@Directive({
  // tslint:disable-next-line:directive-selector
  selector: '[hide]'
})
export class HideDirective implements OnChanges {
  @Input() hide: boolean;

  constructor(private renderer: Renderer2, private elRef: ElementRef) {}

  ngOnChanges() {
    if (this.hide) {
      this.renderer.setStyle(this.elRef.nativeElement, 'visibility', 'hidden');
    } else {
      this.renderer.setStyle(this.elRef.nativeElement, 'visibility', 'visible');
    }
  }
}

results matching ""

    No results matching ""