我想使用主机绑定设置托管组件的宽度,我尝试了以下代码,但是不能?
父组件:
<app-list-comp>
</app-list-comp>
@Hostbinding('') listWidth: number; //what should I pass inside ('')
ngOnChanges({ list }: SimpleChanges): void {
//calculate width depands on the list array length
this.listWidth = list.currentValue.length * 20;
}
子组件(app-list-comp):
<div>//this div needs the width from parent component
<ul>
</ul>
</div>
子组件如何从父组件知道宽度?