tonjel
tonjel

Reputation: 99

Set Auto Refresh Page on Angular 6

I have 3 different page on my angular (im using Angular 6), but im still confusing how to make all of my pages auto refresh/reload with interval time.

Is there any way to make function or etc ? relate to auto refresh/reload in each of page component.ts, component.html, or maybe in app-routing.module ?

Any suggestion or experience to make something like that ?

For example component.ts:

import { Component, OnInit } from '@angular/core';

@Component({
 selector: 'app-example-page',
 templateUrl: './example-page.component.html',
 styleUrls: ['./example-page.component.less']
})
export class ExamplePageComponent implements OnInit {

  constructor() { }

  ngOnInit() {

  }

}

Upvotes: 5

Views: 20912

Answers (1)

MBDev
MBDev

Reputation: 442

Example

import { Observable, interval, Subscription } from 'rxjs';

export class YourComponent ... {

  private updateSubscription: Subscription;

  ngOnInit() {
      this.updateSubscription = interval(1000).subscribe(
        (val) => { this.updateStats()
      }
  );



}

Upvotes: 16

Related Questions