Use the RxJS from operator to create a stream with an array of data. Use the interval and zip operators to time delay each element in the stream.
Instructor: Begin by importing the from operator from RxJS. Next, define an observable using the from operator, passing in an array of numbers. In order to use the observable, we'll subscribe to it and pass in an observer that logs out the value.
As we can see, all of the numbers appear at once. We'll use the interval operator to define an observable that has a time series.
Finally, we'll use the zip operator to define another observable that takes in our from observable and our timed interval observable. We'll subscribe to our zipped observable. As we can see, we're logging an array.
We'll use destructuring assignment to access the first element in that array, the returned number from our from observable.
There we have it, each element in our array appearing in a time-delayed stream.
You must be a Pro Member to view code
Access all courses and lessons, track your progress, gain confidence and expertise.