G
G
Ghoulll2020-06-19 15:36:13
typescript
Ghoulll, 2020-06-19 15:36:13

How to stop interval in RxJS?

It is necessary to stop the interval upon reaching a certain value of the variable timer

timer = 0;

  startTimer(): any {
    interval(1000).subscribe(i => {
      this.timer++;
    });
  }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
twoone, 2020-06-19
@Ghoulll

Rxjs is an amazing library that allows you to implement any scenarios, but requires thinking in abstractions with the ideology it promotes. And if I understand your case correctly, then the easiest way is to use the take operator.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question