我有一个 Observable 名称 changes$,changes$ as observable have ein Property thas 也是一个 Observabl3e。这就是我的界面:
export interface SaveableChange {
comparableValues$: Observable<readonly unknown[]>,
savingIsRunning$: Observable<boolean>,
reset: () => void,
save: () => void,
isSidebar?: boolean,
isValid$?: Observable<boolean>,
}
export type CombinedSaveableChanges = Observable<(SaveableChange & { hasChanged: boolean })[]>
changes$ 是一个 CombinedSaveableChanges! 我想访问 isValid$ 值并在 if funktion 中使用它来确定我是否可以继续进行控制台日志记录。我不确定如何在没有两次订阅的情况下访问有效。如您所见,CombinedSaveableChanges 是一个数组。有什么建议吗?非常感谢。
changes$.pipe(take(1)).subscribe((combinedChanges => {
combinedChanges.forEach(change => {
change.isValid$.subscribe(isValid => {
if (!isValid) {
console.log('valid');
}
console.log('not valid');
});
});
}));
我 ddt 尝试 switsch 地图和两次订阅。使用 swtisch 地图我无法得到结果,并且有两个订阅,写起来不正确。