Skip to content

Instantly share code, notes, and snippets.

@NishuGoel
Created July 27, 2018 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NishuGoel/4b9904497d2f84e345b88fd0d0a05ae4 to your computer and use it in GitHub Desktop.
Save NishuGoel/4b9904497d2f84e345b88fd0d0a05ae4 to your computer and use it in GitHub Desktop.
import { Directive, ElementRef, Renderer, HostListener } from "@angular/core";
@Directive({
selector: '[app-ch-color]'
})
export class bgDirective{
constructor(private el: ElementRef, private renderer: Renderer){
this.changeColor('red');
}
@HostBinding('style.border') border : string;
@HostListener('click') koo(){
this.border = '5px solid yellow';
}
changeColor(color: string){
this.renderer.setElementStyle(this.el.nativeElement, 'color', color);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment