I have a this Observable
obs1$ = this.otherService.getObservable() which is of type number
I want to create a method which emits a Observable using the return value of this Observable
combined() {
this.currentLambdaReactorState$.subscribe((e) => {
let dto = of([
{
name: 'foo',
value: e,
},
])
return dto
});
}
so far this method does not return anything, how can I return a Observable from that method ?
CodePudding user response:
Map is what you want here.
// replace any with your type (returned from currentLambdaReactorState$)
combined(): Observable<{name: string, value: any}> {
return this.currentLambdaReactorState$.pipe(
// shorthand object literal return
map((e)=> ({name: 'foo', value: e}))
)
}
// usage
combined().subscribe((mappedValue) => {
console.log(mappedValue); // {name: 'foo', value: e}
});
CodePudding user response:
You can add return before this.currentLambdaReactorState$ and replace subscribe by map
