Created
April 17, 2020 15:55
-
-
Save NyaGarcia/218bab0b1341955ddad652e34051e4cc to your computer and use it in GitHub Desktop.
Creating Observables with the range() function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { range } from "rxjs"; | |
// Observable will emit a sequence of numbers from 0 to 4 and complete | |
const number$ = range(5); | |
// Observable will emit a sequence of numbers from 1 to 5 and complete | |
const range$ = range(1, 5); | |
// Observable will emit a sequence of 10 numbers starting at 10 (from 10 to 19) | |
const moreNumber$ = range(10, 10); | |
number$.subscribe(number => console.log(number)); | |
// Output: 0, 1, 2, 3, 4, 5 | |
range$.subscribe(console.log); | |
// Output: 1, 2, 3, 4, 5 | |
moreNumber$.subscribe(number => console.log(number)); | |
// Output: 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment