【发布时间】:2019-08-28 19:34:08
【问题描述】:
我有以下 divTable:
<div class="divTable">
<div class="divTableBody">
<div class="divTableRow">
<div class="divTableCell">TagName</div>
<div class="divTableCell">Higher/Lower</div>
<div class="divTableCell">Threshold</div>
<div class="divTableCell">Delete Alert?</div>
</div>
<div class="divTableRow" *ngFor="let com of currentAlerts">
<div class="divTableCell">{{com.tagname}}</div>
<div class="divTableCell">{{com.symbol == 1 ? 'Higher than' : 'Lower than'}}</div>
<div class="divTableCell">{{com.threshold}}</div>
<div class="divTableCell">
<button mat-stroked-button color="primary" (click)="submit(com.ID)">
Delete
</button>
</div>
</div>
</div>
如您所见,此表循环遍历数组 currentAlerts 并为找到的每个项目创建一行。
该数组通过连接到 Web API 在ngOnInit() 中填充。
this.alerts.getCurrentAlerts(this.loginEmail)
.subscribe
((data: CurrentAlerts[]) => {this.currentAlerts = data;
console.log(this.currentAlerts.length)
if(!this.currentAlerts || !this.currentAlerts.length){
this.alertsTitleMessage = "You have no alerts configured."
}else{
this.alertsTitleMessage = "Here are the Alerts you have set up "
}}
);
当点击删除按钮时,删除请求被发送到数据库。
submit(ID){
let isDeleted = null;
this.alerts.deleteCurrentAlert(ID).subscribe(result => isDeleted = result);
this.manageCurrentAlerts();
}
以上所有操作都按预期工作,数据已从数据库中删除。
问题
如何让表格删除已删除的行?我已经阅读了使用splice 从arra 中删除行的答案,但我无法让它工作。
【问题讨论】:
标签: html angular typescript