【发布时间】:2016-12-02 21:01:43
【问题描述】:
如何将元素的 width 属性绑定到模型,然后从模型绑定到另一个开发者?
<div [width1]="style.width.px">
<div [style.width.px]="width2">
export class MyComponent
{
width1: number;
width2: number = width1 - 30;
}
【问题讨论】:
如何将元素的 width 属性绑定到模型,然后从模型绑定到另一个开发者?
<div [width1]="style.width.px">
<div [style.width.px]="width2">
export class MyComponent
{
width1: number;
width2: number = width1 - 30;
}
【问题讨论】:
我会说:
<div #width1>
<div [style.width.px]="width2">
export class MyComponent
{
width1: number;
@ViewChild('width1') width1;
ngAfterViewInit(){
this.width2 = this.width1.nativeElement. width - 30;
}
}
【讨论】: