Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Auto Refresh Page on Angular 6

Tags:

angular

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() {

  }

}
like image 458
tonjel Avatar asked Feb 17 '19 15:02

tonjel


1 Answers

Example

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

export class YourComponent ... {

  private updateSubscription: Subscription;

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



}
like image 183
MBDev Avatar answered Nov 03 '22 00:11

MBDev