Having difficulty organizing a chain of calls using TypeScript with RxJS observables
I am new to RXJS and I am struggling to structure a chain of calls in my TypeScript code. My question is - how can I ensure that this.http.get(''); is only called once? Please note that the code provided is just a simplified example for demonstration purposes.
import {Injectable} from '@angular/core';
import {flatMap, map} from 'rxjs/operators';
import {Observable, from} from 'rxjs';
import {HttpClient} from '@angular/common/http';
@Injectable()
export class CoolService {
constructor(private http: HttpClient) {}
x(): Observable<Object> {
return from(Promise.resolve({a: {b: 'c'}})).pipe(
flatMap((x) => {
console.log(x);
return this.http.get('http://www.gooogle.com');
}), map((res) => {
console.log(res);
return res;
}));
}
}