Ng - Directive - Change backgroundColor

PHOTO EMBED

Thu Feb 25 2021 09:51:42 GMT+0000 (Coordinated Universal Time)

Saved by @Antoine #typescript #javascript #angular

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);
    }
}
content_copyCOPY