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;
}
添加回答
舉報