简体   繁体   中英

How to combine Observable and Subject into combineLatest?

I am new to combineLatest, but i am trying to combine an array which has :

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. But i need them. Please some help. Thank you.

CombineLatest subscription works if every Observable inside has at least one value. Seems when you subscribe, some of your validations don't have value.

You can add start value to it, just add .pipe(startsWith(null)) to each Observable/Subject.

Another way you can use merge(validations) instead if it's convenient.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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