比方说,我有一个用Angular 6创建的网页,我想定期进行一些自动重装或自动获取数据。我一直在寻找线索,唯一的事情是使用角度上可观察到的间隔。
我的问题是,当获取数据的过程通过获取API时如何使用它?我在下面给出我的代码:
dashboard.component.ts
import { interval } from 'rxjs';
import { Observable } from 'rxjs';
import { take } from 'rxjs/operators';
export class DashboardComponent implements OnInit {
constructor(private countryunitservice: CountryunitService){
const theme = this.chartTheme;
this.Highcharts.theme = theme;
this.Highcharts.setOptions(theme);
}
ngOnInit() {
this.countryunitservice.getTicketCountryUnit().subscribe((res)=>{
this.temp = Object.values(res).map(val => +val);
this.Highcharts.chart({
chart: {
type: 'column',
renderTo:'chartContainer',
},
title: {
text: 'IDN'
},
subtitle: {
text: 'Country Unit'
},
xAxis: {
categories: ['In Queue', 'On Progress', 'Finished', 'Failed']
},
series: [{
type: 'column',
colorByPoint: true,
data: this.temp,
showInLegend: false
}]
});
})
}
这是我的CountryUnitService.ts:
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Injectable({
providedIn: 'root'
})
export class CountryunitService {
baseUrl:string = "https://blabla.id/rest/test";
constructor(private httpClient : HttpClient) { }
getTicketCountryUnit(){
return this.httpClient.get(this.baseUrl);
}
}