File

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

Implements

OnInit

Metadata

Index

Methods
Inputs
HostListeners

Constructor

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

Inputs

color
Type : string
Default value : 'red'

HostListeners

mouseenter
mouseleave

Methods

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

@Directive({
    selector: '[appBorder]',
    standalone: true,
})
export class BorderDirective implements OnInit {
    @Input() color: string = 'red';

    constructor(private el: ElementRef) {}

    ngOnInit() {
        this.border('');
    }

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

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

    private border(color: string) {
        this.el.nativeElement.style.border = `2px solid ${color || 'transparent'}`;
    }
}

results matching ""

    No results matching ""