Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import { Directive, ElementRef, Renderer } from '@angular/core';
@Directive({
selector: '[appChbgcolor]'
})
export class ChangeBgColorDirective {
constructor(private el: ElementRef, private renderer: Renderer) {
this.ChangeBgColor('red');
}
ChangeBgColor(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