我有一个设置器,它指定一个类成员可观察到的systemAreasOptions$
。我在那里这样做是因为它需要等待mappedItem$
有一个不为空的发射。我最初在类级别分配了systemAreasOptions$
,但它没有等待mappedItem$
。由于某些原因,在使用asyncPipe
时,我甚至无法让HTML改进型。我如何告诉一个可观察的(systemAreasOptions$
等待另一个可观测的(mappedItem$
) ),而不只是分配它的另一个发射的地方?
public set mappedItem(mappedItem: IPermissionsMappedItem) {
mappedItem.hydrate$Permissions().then(_ => {
this.mappedItem$.next(mappedItem);
this.systemAreasOptions$ = from(
this.lookupService.SYSTEM_AREAS.toNestedLookup()
.$promise as unknown as Observable<IPermissmissionsLookup[]>
).pipe(
map(systemAreas => orderBy(systemAreas,systemArea => systemArea?.label?.toLowerCase())),
map(systemAreas => systemAreas.map(area => ({
...area,
permissions: this.getPermissionsForArea(area.id)
}))),
shareReplay(1),
tap(console.log)
);
this._subscriptions.add(
this.systemAreasOptions$.subscribe(
this.systemAreasOptionsBehaviourSubject$)
);
});
}
发布于 2021-10-14 14:54:10
您可以将可观察到的数据组合在一起:
时,才会发出非空
我敢说你在找withLatestFrom:
higherOrder$ = mappedItemThatIsNotNull$.pipe(
withLatestFrom(systemAreasOptions$)
)
在模板中:
higherOrder$ | async
这将产生mappedItem,systemAreaOptions
https://stackoverflow.com/questions/69577949
复制相似问题