How to get the parent DOM element reference of an angular2 component

前端 未结 5 1862
醉酒成梦
醉酒成梦 2021-01-04 20:32

I need to access to some properties of the parent DOM element which contains the component from where i want to get the info, is there a way to do such thing?

Here i

5条回答
  •  無奈伤痛
    2021-01-04 21:12

    In your child component pass parent in constructor:

      constructor(
        private parent: ParentComponent,
        ...
      )
    
      ngAfterViewInit() {
        console.log(this.parent);
      }
    

提交回复
热议问题