Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call function every 2 mins in angular2? [duplicate]

Tags:

angular

ionic2

How do I call a save function every two minutes in Angular2?

like image 564
Victor Carvalho Avatar asked Mar 21 '16 14:03

Victor Carvalho


1 Answers

rxjs 6

  import { interval } from 'rxjs';    interval(2000 * 60).subscribe(x => {     doSomething();   }); 

rxjs 5

You can either use

import {Observable} from 'rxjs'; // Angular 6  // import {Observable} from 'rxjs/Rx'; // Angular 5    Observable.interval(2000 * 60).subscribe(x => {     doSomething();   }); 

or just setInterval()

Hint:

Angular >= 6.0.0 uses RxJS 6.0.0 Angular Changelog 6.0.0

RxJS v5.x to v6 Update Guide

like image 71
Günter Zöchbauer Avatar answered Oct 03 '22 05:10

Günter Zöchbauer