簡體   English   中英

Angular 組件未從服務獲取數據以傳遞給共享控制

[英]Angular component not getting data from service to pass to shared control

我已經設置了一個基本應用程序,該應用程序調用服務以通過調用公開可觀察對象的服務來獲取數據以傳遞給共享控件。 但是,該服務返回一個空數組。 我試圖弄清楚沒有返回什么數據。

這是一個完整的堆棧閃電戰: https://stackblitz.com/edit/angular-ivy-o5wjvf

您的combineLatest需要訂閱...否則您當前的調用將不會設置userItemsEntityListSubject$的下一個值

您當前的代碼:

  combineLatest(this.userItems$, this.items$).pipe(
      map(([useritems, items]) => {
        console.log(' inside the dataService combineLatest: ', useritems);
        return items
          .filter((i) => !useritems.includes(i.itemId))
          .map((item) => {
            return {
              entityId: item.itemId,
              entityName: item.itemName,
              entityCategory: '',
            };
          });
      })
    ),
      tap((val) => console.log(' the value of moSelectParticipants$: ', val));
    tap((val: IMySelectEntity[]) => this.userItemsEntityListSubject$.next(val));

不知道為什么你把tap放在pipe ,可能是一個糟糕的 C&P

這是修復(請注意combineLatest中的方括號):


combineLatest([this.userItems$, this.items$]).pipe(
      map(([useritems, items]) => {
        console.log(' inside the dataService combineLatest: ', useritems);
        return items
          .filter((i) => !useritems.includes(i.itemId))
          .map((item) => {
            return {
              entityId: item.itemId,
              entityName: item.itemName,
              entityCategory: '',
            };
          });
      }),
    ).subscribe(items => this.userItemsEntityListSubject$.next(items))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM