Mathers
Mathers

Reputation: 184

Angular2 Directive hostListeners does not exist in type 'Directive'

When I try to use hostListeners inside a Directive in my directive.ts, it throws me error: arguments of type {'selector':string, 'hostListeners':{};} is not assignable ...bla bla...

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

@Directive({
    selector: '[moduleOpt]',
    hostListeners: {

    }
})

export class ModuleOpt implements OnInit{
    @Input() moduleOpt: Array<any>;

    constructor(){}

    ngOnInit() {

    }

}

Can someone help me with this?

Upvotes: 1

Views: 221

Answers (1)

G&#252;nter Z&#246;chbauer
G&#252;nter Z&#246;chbauer

Reputation: 657761

@Directive({
    selector: '[moduleOpt]',
    host: {
      '(xxx)': 'yyy'
    }
})

or

class MyDirective {
  @HostListener('xxx', ['$event'])
  yyy(event) {
    console.log(event);
  }
}

Upvotes: 2

Related Questions