我有一个输入和一个表。
<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)
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)