How to remove specific element from Observable>

前端 未结 4 1116
你的背包
你的背包 2020-12-15 20:22

There is an Observable of the array of places:

places: Observable>;

In template it used with the async pipe:

4条回答
  •  既然无缘
    2020-12-15 20:37

    The filter function is immutable and won't change the original array.

    I would change the deletePlace function to something like this:-

    deletePlace(placeId: number):  void {
      this.apiService.deletePlace(placeId)
      .subscribe(
        (res: any) => {
          this.places = this.places.filter((place) => place.id != placeId);
        }, 
        (err: any) => console.log(err)
      );    
    }  
    

提交回复
热议问题