How to make an http call every 2 minutes with RXJS?

前端 未结 5 418
猫巷女王i
猫巷女王i 2020-12-03 05:14

I have a service that will make a call to my rest service every 2 minutes. On my service I have the following function

  getNotifications(token: string) {
           


        
5条回答
  •  生来不讨喜
    2020-12-03 06:14

    import {Observable} from 'rxjs/Rx';
    
      Observable.interval(2 * 60 * 1000).subscribe(x => {
        callyourmethod();
      });
    

    Update After comment

    this.interval = setInterval(() => {
            this.yourservicecallmethod();
        }, 2 * 60 * 1000);
    

提交回复
热议问题