html - 如何将 div 的宽度绑定(bind)到 angular 2.0 中的模型?

标签 html css angular

如何将元素的宽度属性绑定(bind)到模型,然后从模型绑定(bind)到另一个开发人员?

<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;

  }
}

关于html - 如何将 div 的宽度绑定(bind)到 angular 2.0 中的模型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40931187/

相关文章:

php - HTML 在提交时调用 PHP 函数而不离开页面

css - 如何使CSS成为:active work after the click?

angular - 使用多个服务来填充 Angular 数据表

html - Flowplayer 在 IE9 中找不到视频,在 IE8 及以下版本中找不到不支持的视频

html - 如何在 HTML 中设置十六进制链接网格?

css - @font-face 不适用于 Mobile Safari

css - 使用 Bootstrap 的类在表内调整输入文本的大小

angular - 垫表的单独列过滤器

android - Chrome Android Angular Contenteditable 在修改前验证输入

html - 记住滚动条在 HTML/CSS 表格中的位置