实施可观察到的间隔以在周期时间角度6上获取数据

时间:2019-02-19 18:40:31

标签: angular rxjs observable angular-observable

比方说,我有一个用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);
  }
 }

0 个答案:

没有答案