我的角度上有3个不同的页面(我使用Angular 6),但我仍然混淆如何使我的所有页面自动刷新/重新加载间隔时间。
有没有办法让功能等?与每个页面component.ts,component.html或app-routing.module中的自动刷新/重新加载有关?
有什么建议或经验可以做出类似的事情吗?
例如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() {
}
}
例
import { Observable, interval, Subscription } from 'rxjs';
export class YourComponent ... {
private updateSubscription: Subscription;
ngOnInit() {
this.updateSubscription = interval(1000).subscribe(
(val) => { this.updateStats()
}
);
ngOnDestroy() {
this.updateSubscription.unsubscribe();
}
private updateStats() {
console.log('I am doing something every second');
}
}