Как получить доступ к любому элементу в директиве и добавить события? - PullRequest
0 голосов
/ 29 апреля 2018

Вот моя директива:

import { Directive, HostListener, ElementRef, Renderer, Input } from '@angular/core';

@Directive({
  selector: '[carouselDirective]'
})
export class CarouselDirective {

    @Input() carouselDirective:any;

    constructor( private el : ElementRef, private renderer: Renderer ) { 
        console.log(el.nativeElement); //how to add the click / hover events to it's childrens?
    }

    @HostListener('click') onClick() {
        window.alert("onClick");
    }

    @HostListener('mouseover') onHover() {
        window.alert("hover");
    }

}

Мой вопрос:

1. how to add any of the events to any of the children of my directive? ( on event i require to add and remove some class names )
2. how to communicate with his parent component?
3. how to get some value from parent component and manipulate in directive?
4. can't I add remove class name to child elements?
5. on click of child element can't i change property of parent element?
6. if there is 5 element under a parent to add events to them, required to create separate 5 directive(s"?
...