简体   繁体   English

如何将 Observable 和 Subject 组合成 combineLatest?

[英]How to combine Observable and Subject into combineLatest?

I am new to combineLatest, but i am trying to combine an array which has :我是 combineLatest 的新手,但我正在尝试组合一个具有以下功能的数组:

0: Observable {_isScalar: false, _subscribe: ƒ}
1: Observable {_isScalar: false, _subscribe: ƒ}
2: Observable {_isScalar: false, _subscribe: ƒ}
3: Subject {_isScalar: false, observers: Array(0), closed: false, isStopped: false, hasError: false, …}
4: Subject {_isScalar: false, observers: Array(0), closed: false, isStopped: false, hasError: false, …}
5: Observable {_isScalar: false, _subscribe: ƒ}
6: Observable {_isScalar: false, _subscribe: ƒ}

But for some reason the但由于某种原因

combineLatest(validations).subscribe(result => {console.log("it works"});

Doesn't fired up.不发火。 I am new to this function and there is no error messages which makes it impossible for me to understand what is wrong.我是这个功能的新手,没有错误消息让我无法理解什么是错误的。 if i remove the items 3-4 it fires.如果我删除项目 3-4 它会触发。 But i need them.但我需要它们。 Please some help.请一些帮助。 Thank you.谢谢你。

CombineLatest subscription works if every Observable inside has at least one value.如果内部的每个Observable至少有一个值,CombineLatest 订阅就可以工作。 Seems when you subscribe, some of your validations don't have value.似乎当您订阅时,您的某些validations没有价值。

You can add start value to it, just add .pipe(startsWith(null)) to each Observable/Subject.您可以为其添加.pipe(startsWith(null)) ,只需将.pipe(startsWith(null))到每个 Observable/Subject。

Another way you can use merge(validations) instead if it's convenient.如果方便,您可以改用merge(validations)另一种方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM