mirror of
https://github.com/akveo/ngx-admin.git
synced 2025-09-22 05:50:48 +02:00

With this change all components, which used data services before, now use abstract classes of service interfaces, mock services extend interface services, CoreModule contains code to inject a needed implementation of some service.
48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
import { Component, OnDestroy } from '@angular/core';
|
|
import { NbThemeService } from '@nebular/theme';
|
|
|
|
import { Electricity, ElectricityChart, ElectricityData } from '../../../@core/data/electricity';
|
|
import { takeWhile } from 'rxjs/operators';
|
|
import { forkJoin } from 'rxjs';
|
|
|
|
@Component({
|
|
selector: 'ngx-electricity',
|
|
styleUrls: ['./electricity.component.scss'],
|
|
templateUrl: './electricity.component.html',
|
|
})
|
|
export class ElectricityComponent implements OnDestroy {
|
|
|
|
private alive = true;
|
|
|
|
listData: Electricity[];
|
|
chartData: ElectricityChart[];
|
|
|
|
type = 'week';
|
|
types = ['week', 'month', 'year'];
|
|
|
|
currentTheme: string;
|
|
themeSubscription: any;
|
|
|
|
constructor(private electricityService: ElectricityData,
|
|
private themeService: NbThemeService) {
|
|
this.themeService.getJsTheme()
|
|
.pipe(takeWhile(() => this.alive))
|
|
.subscribe(theme => {
|
|
this.currentTheme = theme.name;
|
|
});
|
|
|
|
forkJoin(
|
|
this.electricityService.getListData(),
|
|
this.electricityService.getChartData(),
|
|
)
|
|
.pipe(takeWhile(() => this.alive))
|
|
.subscribe(([listData, chartData]: [Electricity[], ElectricityChart[]] ) => {
|
|
this.listData = listData;
|
|
this.chartData = chartData;
|
|
});
|
|
}
|
|
|
|
ngOnDestroy() {
|
|
this.alive = false;
|
|
}
|
|
}
|