Home > Blockchain >  How to combine Observable and Subject into combineLatest?
How to combine Observable and Subject into combineLatest?

Time:10-21

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.

CodePudding user response:

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.

  • Related