Answer the question
In order to leave comments, you need to log in
How to merge two requests using mergeMap?
I would like to do the following: use an observable to track clicks in an area of the page. And after each click, send a request to get a list of github users.
I can create two separate requests and send them in turn. But would like to merge these two queries using mergeMap. Here is my attempt:
constructor(private httpClient: HttpClient) { }
ngOnInit() {
Observable.fromEvent(document, 'click')
.mergeMap(() => this.httpClient.get('https://api.github.com/users'))
.subscribe((e) => {
console.log(e);
//console.log(e['pageX'], e['pageY']);
});
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question