I have an input and a table.
JavaScript
x
3
1
<input type="search"/>
2
<table id="myTable"/>
3
How can I bind the width of my input to the same width of the table?
Something like this?
JavaScript
1
2
1
<input type="search" [style.width]="#myTable.width"/>
2
Advertisement
Answer
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
:
JavaScript
1
3
1
<input [ngStyle]="{'width.px': myTable.offsetWidth }">
2
<table #myTable>...</table>
3
In the above code, the table tag width will match input’s width.