【问题标题】:How to bind div's width to a model in angular 2.0?如何将 div 的宽度绑定到 angular 2.0 中的模型?
【发布时间】: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;
}

【问题讨论】:

    标签: html css angular


    【解决方案1】:

    我会说:

    <div #width1>
    <div [style.width.px]="width2">
    
    export class MyComponent
    {
    width1: number;
     @ViewChild('width1') width1;
    
    
     ngAfterViewInit(){
        this.width2  = this.width1.nativeElement. width - 30;
    
      }
    }
    

    【讨论】:

    • width1 在 ngAfterViewInit() 中未定义
    猜你喜欢
    • 2011-08-02
    • 2016-04-11
    • 1970-01-01
    • 1970-01-01
    • 2020-10-05
    • 1970-01-01
    • 1970-01-01
    • 2019-12-25
    • 2015-08-18
    相关资源
    最近更新 更多