【发布时间】:2018-02-13 17:08:47
【问题描述】:
我正在尝试在父组件的 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'
};
}
}
是否可以使用此方法(不是我现在所说的方式,因为它会连续给出编译时错误和不希望的运行时行为)?或者当它在这个地方渲染时组件还没有被实例化,这需要以某种不同的方式完成吗?
【问题讨论】:
标签: angular angular2-template angular2-databinding