我有一个父组件,在该TS文件中,我获得如下元素ref:
@ViewChild("custContainer") _custContainer: ElementRef;
const height = this._custContainer.nativeElement.height;
然后我有一个子组件,我需要在那里访问这个父ElementRef。我如何在子组件中做到这一点,我认为我需要在父组件渲染后获得它,因为一旦数据加载到此元素中,我就使用它来获得高度。
如果要访问子组件内部的高度,则可以在子组件中使用@Input
属性。
子组件中
.ts
@Input() height;
并且从父组件html
<child-comp [height]="height"></child-comp>