map vs switchMap in RxJS
Both operators are different. switchMap: Maps values to observable. Cancels the previous inner observable. Eg: fromEvent(document, ‘click’) .pipe( // restart counter on every click // First click: 0, 1, 2… // Second click: cancels the previous interval and starts new one. 0, 1, 2… switchMap(() => interval(1000)) ) .subscribe(console.log); map: Add projection with each value. … Read more