How to find children and parents of a DOM element in Angular2

Try to use your code in ngAfterViewInit event.

And you need to use parentNode property instead parent

export class App {
  el: ElementRef;
  constructor(el: ElementRef){
    this.el = el; 
  },
  ngAfterViewInit() {
    const hostElem = this.el.nativeElement;
    console.log(hostElem.children);
    console.log(hostElem.parentNode);
  }
}

https://plnkr.co/edit/iTmsNaIoU9NNUEFRe4kG?p=preview

Leave a Comment