V
V
Vladimir2021-09-26 17:33:57
Angular
Vladimir, 2021-09-26 17:33:57

Why doesn't @Directive (namely the class with logic) work in angular?

Hello. Please tell me why it is highlighted in red and does not work? I google, there are answers for 2015, generally a different syntax. Maybe I forgot to install some package? I haven't found anything in the documentation yet.

import { Component, Directive, HostListener, ElementRef } from '@angular/core';
import {LoggerService} from "./logger.service";

@Directive({
    selector: '.title'
})

class HighlightDirective {

    constructor(private el: ElementRef) { }

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

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

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

}

@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.scss']
})

export class AppComponent { ... }


615085007698d165313107.png

I would be grateful for any help!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Kadyrov, 2022-01-30
@Ahmad66617

The answer can be banal to disgrace - such highlighting most likely indicates that you did not declare and did not import the directive in the module

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question