1 回答
TA贡献1796条经验 获得超4个赞
为了获得从模板到组件的高度,您可以使用 @ViewChild()... 完整的工作示例在这个StackBlitz Link中
// your HTML file is..
<div style="width:50vw; margin: 0 auto; border: 1px solid red; padding:1rem; text-align:center" #barcode>
<app-barcode [ObjectHeight]="barcodeHeight" >
</app-barcode>
</div>
// 你的 Component.ts 是 ...
@ViewChild ('barcode', {static:true}) barcode : ElementRef;
constructor(private cdr: ChangeDetectorRef){}
ngAfterViewInit(){
this.barcodeHeight= this.barcode.nativeElement.clientHeight;
this.cdr.detectChanges();
}
// 您的条码 Component.ts 是...
height;
@Input ('ObjectHeight') set heightFromApp(value){
this.height= value;
}
添加回答
举报
