HI WELCOME TO KANSIRIS

Call a function every 10 seconds Angular2

Leave a Comment

 from RxJS 6+ you just use interval.

import { interval } from 'rxjs';

//in 10 seconds do something
interval(10000).subscribe(x => {
    this.myFunctionThatDoesStuff();
});

you can use Subscription with the interval.

import { interval, Subscription} from 'rxjs';
export class intervalDemo{
    mySubscription: Subscription

    constructor(){
    this.mySubscription= interval(5000).subscribe((x =>{
                this.doStuff();
            }));
    }
    doStuff(){
        //doing stuff with unsubscribe at end to only run once
        this.failedRequestSub.unsubscribe();
    }
}

0 comments:

Post a Comment

Note: only a member of this blog may post a comment.