angular - Angular 2 - 向表格单元格中的按钮添加点击功能
问题描述
这是我的 HTML:
<div>
<article class="content">
<section>
<div class="table-responsive">
<table class="table highlight">
<tr>
<th *ngFor="let head of heads">{{head}}</th>
</tr>
<tr *ngFor="let body of bodys">
<td *ngFor="let p of body" [innerHTML]="p"></td>
</tr>
</table>
</div>
</section>
</article>
</div>
这是我的.ts:
for (var i in this.products){
var wp = this.products[i];
var temp = [];
temp.push("x");
temp.push("x");
temp.push("x");
temp.push('<a class="tbl-btn btn-primary (click)="termsheetClicked()">View Termsheet</a>');
temp.push('<a class="tbl-btn btn-primary">View Product Offering</a>');
this.bodys.push(temp);
}
但是, termsheetClicked() 从未调用过。
解决方案
我找到了一个替代方案。我没有从 .ts 添加按钮,而是通过 HTML 添加按钮,如下所示:
<div>
<article class="content">
<section>
<div class="table-responsive">
<table class="table highlight">
<tr>
<th *ngFor="let wpHead of wpHeads">{{wpHead}}</th>
</tr>
<tr *ngFor="let wpBody of wpBodys">
<td>{{wpBody[0]}}</td>
<td>{{wpBody[1]}}</td>
<td>{{wpBody[2]}}</td>
<td><button class="tbl-btn btn-primary" (click)="termsheetClicked(wpBody[3])">View Termsheet</button></td>
<td><button class="tbl-btn btn-primary" (click)="termsheetClicked(wpBody[4])">View Product Offering</button></td>
</tr>
</table>
</div>
</section>
</article>
</div>
推荐阅读
- html - CSS 和 Bootstrap:创建一条连接行的线
- react-native - 无法使用 react-native-calendars
- ubuntu - 在 Ubuntu 19.04 上安装 Redis-Commander 作为服务
- c - C 编程指针和数组
- google-bigquery - 为什么 Bigquery 会使用以下消息取消我的工作:用户请求取消
- c# - 错误消息“System.Security.VerificationException:操作可能会破坏运行时。” 使用 iText7 从 pdf 中提取文本时
- powerbi - 如何非规范化 Power BI 单元格中的表
- firebase - 将 Firebase 嵌入其他框架的问题
- java - 如果python中没有实际的“null”,python文件阅读器如何停止
- ruby-on-rails - 如何抓取具有自动滚动和延迟加载的数据