Created
November 28, 2018 15:17
-
-
Save NishuGoel/c7cb4d94fca191850fd368097979e81b to your computer and use it in GitHub Desktop.
This file contains 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
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'); | |
} | |
@HostListener('click') foo(){ | |
console.log('Host Element is clicked'); | |
this.changeColor('green'); | |
} | |
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