Files
wahlrecht/module-frontend/src/app/dashboard/dashboard.component.ts
T
2023-07-16 21:56:43 +02:00

32 lines
940 B
TypeScript

import {Component, OnDestroy, OnInit} from '@angular/core';
import {MatTableDataSource} from "@angular/material/table";
import {ElectionService} from "../elections/election.service";
import {Election} from "../elections/election";
import {Subscription} from "rxjs";
@Component({
selector: 'app-dashboard',
templateUrl: './dashboard.component.html',
styleUrls: ['./dashboard.component.scss']
})
export class DashboardComponent implements OnInit, OnDestroy {
electionColumns = ['name', 'day', 'totalNumberOfSeats', 'votingThreshold'];
dataSource = new MatTableDataSource<Election>();
private subscription: Subscription|null = null;
constructor(private electionService: ElectionService) {
}
ngOnInit() {
this.subscription = this.electionService.getElections().subscribe(
(elections) => {
this.dataSource.data = elections;
}
);
}
ngOnDestroy() {
this.subscription?.unsubscribe();
}
}