【发布时间】:2018-11-24 19:11:04
【问题描述】:
我试图从 *ngFor 循环中获取 id 值到我的组件中的方法中,以便删除特定对象 我的代码如下所示:
html:
<tr *ngFor="let c of myCompanyArray">
<td>{{c.id}}</td>
<td>{{c.companyName}}</td>
<td>{{c.password}}</td>
<td>{{c.email}}</td>
<td>
<a href="" class="tooltip">
<i class="fas fa-user-edit"></i>
<span class="tooltiptext">edit company</span>
</a>
</td>
<td>
<a class="tooltip" >
<i class="far fa-trash-alt" (click)="sendIdForDelete({{c.id}})"></i>
<span class="tooltiptext">delete company</span>
</a>
</td>
</tr>
组件:
sendIdForDelete(compid){
console.log("company id is : " + compid.value);
///this.dataService.deleteCompany(compid.value);
}
我在 (click)="sendIdForDelete({{c.id}}) 或 (click)="sendIdForDelete(c.id)" 中尝试过的任何语法我总是不确定 非常感谢您的帮助,谢谢
【问题讨论】:
-
这是因为您编写了“compid.value”,而不仅仅是“compid”。我假设 compid 是一个原语(字符串/数字),所以你不需要 .value 属性来访问它。