I am trying to create a backdrop-click function, which should read the parent of my targeted element. This works so far, but when I want to read the parent of an, ngFor generated, element I get null.
onMouseDown(event: MouseEvent) {
if(event.target === this.elRef.nativeElement || this.isDescendant(this.elRef.nativeElement, event.target)) {
if (this.state === 'OPEN')
this.state = 'CLOSE';
else
this.state = 'OPEN';
this.toggle.emit();
return;
}
isDescendant(parent: any, child: any) {
let node: any = child.parentNode; // does not work on ngFor generated elements
while (node !== null) {
if (node === parent) {
return true;
}
node = node.parentNode;
}
return false;
}
Maybe someone knows how to avoid this problem? Thank you in advance!
best regards Jonaz