【发布时间】:2018-01-21 04:16:17
【问题描述】:
在 restaurant.component.ts 上
我想从arrayList 中删除一个项目并在删除后更新它。查询正在执行删除操作,但列表未更新。我正在调用 ngOnInit() 方法,但没有任何反应
ngOnInit() {
this.restaurantesService.GetRestaurantes()
.subscribe((restaurantes => {
this.restaurantes = restaurantes;
}))
}
qDeleteRestaurantes(CODIGO: number){
var restaurantes = this.restaurantes;
this.restaurantesService.DeleteRestaurantes(CODIGO)
.subscribe((data) => { if (data.n ==1 ){
for(let i=0;i<restaurantes.length;i++){
if(restaurantes[i].CODIGO == CODIGO){
this.restaurantes.splice(i,1);
this.ngOnInit();
}
}
}})
}
【问题讨论】:
-
你确定你打到了
if,所以ngOnInit被再次调用。另外作为评论,不要调用ngOnInit,而是再次调用请求以获取餐厅。另外,如果您想在那之后再次取回餐厅,那您为什么要做splice。splice是多余的,因为您要再次获取餐馆。
标签: angular rest api typescript