在hostListener中添加“ document:click”是什么意思?

时间:2019-07-12 04:38:28

标签: javascript angular angular2-directives

我试图检测设置了元素指令之外的点击事件,但我不明白document: click的含义

@Directive({
  selector: '[appDropdown]'
})

export class DropdownDirective {
  @HostBinding('class.open') private open = false;

  @HostListener('document:click', ['$event']) onClicks() {
    // this.open = !this.open;
    this.open = this.elRef.nativeElement.contains(event.target) ? !this.open : false;
  }
}

0 个答案:

没有答案