如何在Angular 2-HTML中绑定另一个元素的宽度?

ala*_*a27 2 html size angular

我有一个输入和一个表。

<input type="search"/>
<table id="myTable"/>
Run Code Online (Sandbox Code Playgroud)

如何将输入的宽度绑定到表的相同宽度?

像这样吗

<input type="search" [style.width]="#myTable.width"/>
Run Code Online (Sandbox Code Playgroud)

Veg*_*ega 5

The reference in input tag should be for the <table>'s template variable, not the id. # is not necessary when using it in the expressions. You also need to retrieve the offsetWidth and not the width:

<input [ngStyle]="{'width.px': myTable.offsetWidth }">
<table #myTable>...</table>
Run Code Online (Sandbox Code Playgroud)

DEMO

  • 在寻找制作固定表格页眉和页脚的方法后,这挽救了我的一天 (2认同)