In the previous section, we saw the map() operator and how we can use it to map an object into another object in an observable. The flatMap() operator works similarly. It receives a function as a parameter. The function provided as argument must returns an Observable, and the elements of this Observable is propagated instead.
This operator may seen a little bit confusing, but there is another way to understand it. The flatMap() operator runs the given function for each element in the original array. It creates an Observable that will emit each piece of data coming out from other Observables keeping the order.
The flatMap() operator is illustrated in the following signature:
observable.flatMap(flatMapFunction,[thisContext]);
The first parameter is mandatory and the second is optional:
- flatMapFunction: This is a function that takes an element of the observable as input and returns another...