farcasmihai91
4/21/2018 - 8:01 AM

Angular - Directive that Selects a Class

@Directive({
  selector: '.class'
})
export class ClassSelectorDirective implements OnInit {
  elem: HTMLElement;
  constructor(element: ElementRef, private ren: Renderer2) {
    if (element && element.nativeElement) {
      this.elem = element.nativeElement;
    }
  }
  ngOnInit(): void {
    if (this.elem) {
      this.ren.setStyle(this.elem, 'color', 'blue');
    }
  }
}