Prido's avatar
Level 2

Detect if nested child element is contained by parrent element in typescript

Trying to detect if click event.target is child of an element

@viewChild('parentEl', {static: true} ) parentElement: ElementRef;

this.renderer.listen('window','click', (e: Event) => {
console.log(this.parentElement.nativeElement.contains(e.target));
}

When we click on the nested child element console logs false yet the parent element contains the nested child. So it is suppose to log true. Am i missing something?

0 likes
0 replies

Please or to participate in this conversation.