如何访问指令下的任何元素并添加事件?

时间:2018-04-29 15:04:28

标签: angular angular5 angular-directive

这是我的指示:

 a = 0
//if it was 5m time frame a=1
//if it was 15m time frame a=2
//if it was 45m time frame a=3
//if it was 60 time frame a=4

a = is5mTimePeriod ? 1 : is15mTimeperiod ? 2 : .............

我的问题是:

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

}

0 个答案:

没有答案