Reputation: 735
I have an observable with array. I need to make some operation on each element in the array on mouse click event. I started with something like this:
merge([
this.clicks,
this.array$
]).pipe(
tap((value) => console.log(value))
).subscribe();
But how can i iterate the elements, so in each click it will print the next element in the array?
Upvotes: 0
Views: 225
Reputation: 6424
How about the following?
arrayObservable = of(["how", "are", "you"]);
fromEvent(window, "click").pipe(
switchMapTo(arrayObservable$),
map((array, index) => {
return array[index % array.length]
})
)
Hope it helps!
Upvotes: 1