![](/img/trans.png)
[英]Attaching data to a button in a cell from a row in a table that is dynamically generated
[英]Angular invoke TS method by pressing button, attaching rows to table dynamically
我正在尝试创建一个按钮,通过按下该按钮可以向表中动态添加行。 但是,当我尝试在TS( save_row()
)中调用该函数时,它将引发错误。
如何在TS中调用函数/如何通过按动按钮动态添加行?
HTML:
<table id="myTable">
<thead>
<tr>
<th>GEOGRAPHY</th>
<th>COUNTRY</th>
<th>STATE</th>
<th>REGULATION</th>
<th>SMS</th>
<th>WEB</th>
<th>EMAIL</th>
<th>OPERATION</th>
</tr>
</thead>
<tbody #ir>
</tbody>
</table>
打字稿:
var d=geo_Value;
var len=d.length;
var row = this.renderer.createElement('tr');
const col=this.renderer.createElement('td');
row.appendChild(col);
col.outerHTML ="<tr id='row"+len+"'><td
id='name_row"+geo_Value+"'>"+cou_Value+"</td><input type='button'
id='save_button' value='Save' class='save' onclick='save_row("+len+")'>
</td></tr>";
this.renderer.appendChild(this.ir.nativeElement,row);
let idGet=document.querySelectorAll('#save_button');
var myMessage = "it's working";
function save_row(a) {
}
在角度,事件绑定应该是这样的
id='save_button' value='Save' class='save' (onclick)='save_row("+len+")'>
您缺少括号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.