[英]Angular component not getting data from service to pass to shared control
I've set up a basic app that calls a service to get data to pass to a shared control by calling a service that exposes an observable.我已经设置了一个基本应用程序,该应用程序调用服务以通过调用公开可观察对象的服务来获取数据以传递给共享控件。 However, the service is returning an empty array.
但是,该服务返回一个空数组。 I'm am trying to figure out what the data is not being returned.
我试图弄清楚没有返回什么数据。
Here is a full stackblitz: https://stackblitz.com/edit/angular-ivy-o5wjvf这是一个完整的堆栈闪电战: https://stackblitz.com/edit/angular-ivy-o5wjvf
your combineLatest
needs to be subscribed to... otherwise your current call will not set the next value of userItemsEntityListSubject$
您的
combineLatest
需要订阅...否则您当前的调用将不会设置userItemsEntityListSubject$
的下一个值
your current code:您当前的代码:
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));
not sure why you left the tap
out of the pipe
, maybe was a bad C&P不知道为什么你把
tap
放在pipe
,可能是一个糟糕的 C&P
this is the fix (please also notice the square brackets in the combineLatest
):这是修复(请注意
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.