Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 如何以角度(模糊)元素,除非它';在子元素中单击_Angular - Fatal编程技术网

Angular 如何以角度(模糊)元素,除非它';在子元素中单击

Angular 如何以角度(模糊)元素,除非它';在子元素中单击,angular,Angular,如何使用模糊,但在子元素中单击时不激活模糊? 我无法触发li元素上的单击事件 {{selected}} {{item}} 如果您想要一个类似弹出窗口的“点击框外必须关闭框”,那么您可以在文档上注册一个点击监听器,并确定点击是否在框区之外: export class BoxComponent { openedBox = false; @ViewChild('box', { read: ElementRef }) boxRef: ElementRef; @Ho

如何使用模糊,但在子元素中单击时不激活模糊? 我无法触发
li
元素上的单击事件


{{selected}}
    {{item}}
如果您想要一个类似弹出窗口的“点击框外必须关闭框”,那么您可以在
文档
上注册一个
点击
监听器,并确定点击是否在框区之外:

export class BoxComponent {

    openedBox = false;

    @ViewChild('box', { read: ElementRef }) boxRef: ElementRef;

    @HostListener('document:click', ['$event'])
    clickOutsideCurrentPopup(event: Event) {
        if (this.openedBox) {
            // if clicked outside only
            if (!this.boxRef.nativeElement.contains(event.target)) {
                this.openedBox = false; // or do whatever you want to close your box
            }
        }
        // else is already closed, do nothing
    }
}

你能提供更多关于你想要达到的目标的信息吗?可能是结果什么的。或者一些stackblitz演示,当用户点击一个按钮时重现您的问题。列表将被激活并显示。当用户单击此列表之外时,此列表必须消失。但问题是,当用户在列表中单击时,它也会激活模糊事件。这就是我想要阻止的。