我试图检测设置了元素指令之外的点击事件,但我不明白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;
}
}