File

src/app/shared/directives/highlight.directive.ts

Metadata

Index

Methods
Inputs
HostListeners

Constructor

constructor(el: ElementRef)
Parameters :
Name Type Optional
el ElementRef No

Inputs

color
Type : string
Default value : 'yellow'

HostListeners

mouseenter
mouseleave

Methods

Private highlight
highlight(color: string)
Parameters :
Name Type Optional
color string No
Returns : void
onMouseEnter
onMouseEnter()
Decorators :
@HostListener('mouseenter')
Returns : void
onMouseLeave
onMouseLeave()
Decorators :
@HostListener('mouseleave')
Returns : void
import { Directive, ElementRef, HostListener, Input } from '@angular/core';

@Directive({
    selector: '[appHighlight]',
    standalone: true,
})
export class HighlightDirective {
    @Input() color = 'yellow';

    constructor(private el: ElementRef) {}

    @HostListener('mouseenter') onMouseEnter() {
        this.highlight(this.color);
    }

    @HostListener('mouseleave') onMouseLeave() {
        this.highlight('');
    }

    private highlight(color: string) {
        this.el.nativeElement.style.backgroundColor = color;
    }
}

results matching ""

    No results matching ""