我正在尝试在父组件的 html 中设置组件的宽度和高度以及其初始声明。具有以下组件标记(在父级的 html 中):
<app-ipe-artboard [artboard]="artboard" [ngStyle]="setStyle()"></app-ipe-artboard>
setStyle()
画板组件(本身)上的方法在哪里:
@Component({
selector: 'app-ipe-artboard'
})
export class ArtboardComponent implements OnInit {
@Input() public artboard: Artboard;
ngOnInit() {
}
setStyle(): object {
return {
width: this.artboard.width + 'px',
height: this.artboard.height + 'px'
};
}
}
是否有可能达到这种方法(不是我现在所说的方式,因为它会连续给出编译时错误和不希望的运行时行为)?或者当它在这个地方渲染时组件还没有被实例化,这需要以某种不同的方式完成吗?