Issue
How do I make this line return a value in the subscribe ? It is returning an observable instead:
let test = undefined;
of(test, this.myService.whatever(var1, var2))
.pipe(
first(n=>!!n)
).subscribe(result=>console.log(result)); // returns Observable, should return value.
myservice.whatever returns an observable. I want to make it resolve inside pipe. Something like this:
let test = undefined;
of(test, this.myService.whatever(var1, var2))
.pipe(
first(n=>!!n),
getValueFromObserver() // if it's an observer get the value
).subscribe(result=>console.log(result));
Is this possible ? What I'm trying to do is check inside the observer's sequence if a local variable has a value and if it doesn't, then get the value from the backend. I want to make this because the real code is far more complex and the result of this observable will be forkJoined with other observers.
Solution
haven't fully tested but theoretically, you can check instanceof
let test = undefined;
of(test, this.myService.whatever(var1, var2))
.pipe(
first(n => !!n),
switchMap(value => value instanceof Observable ? value : of(value))
).subscribe(result => console.log(result));
Answered By - Fan Cheung
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.