【发布时间】:2019-02-19 17:44:25
【问题描述】:
我在对 Angular 了解不多的情况下使用 Angular 完成了一个正在运行的项目。我目前正在开发一个简单的 CRUD 屏幕。删除一行后,我该如何“刷新” UI?以下是我的组件中的方法:
AATList:IAat[];
confirmDelete(): void{
//this.myService.deleteAAT(this.satNumber).subscribe(data => {this.AATList = data;});
//this.myService.deleteAAT(this.satNumber).subscribe(() => {this.getAATtEntries(); });
this.myService.deleteAAT(this.satNumber).subscribe();
this.getAatEntries();
this.modalRef.hide();
}
getAATtEntries() {
console.log("entries");
this.myService.getAATList().subscribe(data => {this.AATList = data});
}
(在编辑时添加,在组件内部):
openDeleteModal(template: TemplateRef<any>, satNumber: number) {
this.satNumber = satNumber;
this.modalRef = this.modalService.show(template, {class: 'modal-sm'});
}
服务:
getAATList() {
return this.httpClient.get<ISmt[]>(environment.ApiEndPoint + '/api/SMTDatas', {withCredentials:true});
}
deleteAAT(satNumber : number) {
return this.httpClient.delete(environment.ApiEndPoint + '/api/SMTDatas/' + satNumber, {withCredentials:true} )
}
(我使用来自@angular/common/http 的HttpClient 来提供服务)
我已经尝试了 confirmDelete 方法的前三行,但没有成功。我在这里想念什么?我对 Angular 的掌握不是很好,所以请随时指出其他任何内容。
更新: HTML:
<a class="text-danger" data-toggle="tooltip" data-placement="top" title="Delete" (click)="openDeleteModal(deleteTemplate, smt.SMTNumber)"><i class="fa fa-trash"></i>Delete</a>
...
<ng-template #deleteTemplate>
<div class="modal-body text-center">
<p>Are you sure you want to delete this SAT?</p>
<button type="button" class="btn btn-default" (click)="confirmDelete()" >Yes</button>
<button type="button" class="btn btn-primary" (click)="denyDelete()" >No</button>
</div>
</ng-template>
【问题讨论】:
-
我想你可以订阅 modelRef.hide 方法。您可以尝试一下并在订阅时调用 get 方法。像 this.modelRef.hide().subscribe(result=>{this.getAATtentries();});
-
getAATList返回ISmt的列表并将其分配给getAATtEntries中的IAat列表,它们是否具有相同的字段? -
@ZearaeZ 看来我做不到。 “void”类型上不存在属性“subscribe”
-
@WaelAbbas 是的,他们确实有相同的字段
-
@ZearaeZ 您正在使用哪个模态
modalRef组件?
标签: angular typescript get