如何用删除可观察到的 - 角

发布于 2025-02-11 09:29:18 字数 1570 浏览 2 评论 0原文

我试图从可观察到的所有内容中删除所有内容,但它不起作用:

这是我到目前为止所做的:

    deleteAllHistory(Histories$:Observable<History[]>){
    Histories$.forEach((history)=>{this.deleteHistory(history.id)})
  }

当我单击组件中的按钮时,我会触发此功能。这是处理我的组件.ts中删除的功能:

Histories$=this.facade.Histories$;

histo:History[];

this.Histories$.subscribe(history => {
        this.histo = history as History[];
        
    })

onDeleteAll(){
        this.historyService.deleteAllHistory(this.histo);
      }

但是它没有删除任何内容,我想是因为我必须从可观察的:历史记录$中删除。

谢谢您的宝贵时间!

根据要求,帖子呼叫:

addHistory(history:History){
    return this.http.post(this.apiURL, history);
  }

这是模板的标准:

<ng-container *ngIf="Histories$ | async">
                <ng-container
                  *ngFor="let group of Histories$ | async | groupByDay"
                >
                  <strong>{{ group[0] | date:'longDate'}}</strong>
                  <br />
                  <br />
              
                  <div *ngFor="let history of group[1]">
            <mat-list-item  class="historyClicking" (mouseover)="history.showTrash=true" (mouseout)="history.showTrash=false" (click)="onclick()">

                
                <div class="block">
                     
                <div matList>{{history.SNS}}</div>
                <div matList>{{history.title}}</div>
                <div matList>{{history.DMC}}</div>

I am trying to delete everything from an observable but it doesn't work :

This is what I did so far in my service:

    deleteAllHistory(Histories$:Observable<History[]>){
    Histories$.forEach((history)=>{this.deleteHistory(history.id)})
  }

I trigger this function when I click on a button in my component. This is the function that handles deletion in my component .ts :

Histories$=this.facade.Histories$;

histo:History[];

this.Histories$.subscribe(history => {
        this.histo = history as History[];
        
    })

onDeleteAll(){
        this.historyService.deleteAllHistory(this.histo);
      }

But it does not delete anything, I guess because I have to delete from the Observable : Histories$.

Thank you for your time !

As requested, the post call :

addHistory(history:History){
    return this.http.post(this.apiURL, history);
  }

This is par of the template :

<ng-container *ngIf="Histories$ | async">
                <ng-container
                  *ngFor="let group of Histories$ | async | groupByDay"
                >
                  <strong>{{ group[0] | date:'longDate'}}</strong>
                  <br />
                  <br />
              
                  <div *ngFor="let history of group[1]">
            <mat-list-item  class="historyClicking" (mouseover)="history.showTrash=true" (mouseout)="history.showTrash=false" (click)="onclick()">

                
                <div class="block">
                     
                <div matList>{{history.SNS}}</div>
                <div matList>{{history.title}}</div>
                <div matList>{{history.DMC}}</div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云巢 2025-02-18 09:29:18

对于HTTP请求,您需要订阅可观察的。
这是使用 forkjoin forkjoin

deleteAllHistory(histories: History[]){
  return Observable.forkJoin(
    ...histories.map(history => this.http.delete(`${this.apiURL}/${history.id}`)
  );
}

onDeleteAll(){
  this.historyService
      .deleteAllHistory(this.histo)
      .subscribe(() => console.log('Deleted all'));
}

For the http request to run you need to subscribe to the observable.
Here is how I would do it using forkJoin

deleteAllHistory(histories: History[]){
  return Observable.forkJoin(
    ...histories.map(history => this.http.delete(`${this.apiURL}/${history.id}`)
  );
}

onDeleteAll(){
  this.historyService
      .deleteAllHistory(this.histo)
      .subscribe(() => console.log('Deleted all'));
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文