source: Farmatiko/ClientApp/src/app/counter/counter.component.ts@ de18858

Last change on this file since de18858 was de18858, checked in by Mile Jankuloski <mile.jankuloski@…>, 2 years ago

Prepared and improved components for data flows

  • Property mode set to 100644
File size: 2.3 KB
Line 
1import { Component, OnInit, ViewChild, Inject } from '@angular/core';
2import { HttpClient } from '@angular/common/http';
3import { HealthFacilities } from '../models/HealthFacilities';
4import { MatTableDataSource } from '@angular/material/table';
5import { MatPaginator } from '@angular/material/paginator';
6import { MatSort } from '@angular/material/sort';
7import { HealthcareWorkers } from '../models/HealthcareWorkers';
8
9@Component({
10 selector: 'app-counter-component',
11 templateUrl: './counter.component.html',
12 styleUrls: ['./counter.component.css']
13})
14export class CounterComponent implements OnInit {
15 public facilities: HealthFacilities[];
16 public workers: HealthcareWorkers[];
17 displayedColumns = ['Име','Општина','Адреса', 'Тип', 'Е-пошта', 'Телефон'];
18 displayedColumnsWorkers = ['Име','Гранка','Установа', 'Назив'];
19 dataSource = new MatTableDataSource<HealthFacilities>();
20 dataSourceWorkers = new MatTableDataSource<HealthcareWorkers>();
21
22 @ViewChild(MatPaginator, {static: true}) paginator: MatPaginator;
23 @ViewChild(MatSort) sort: MatSort;
24
25 constructor(http: HttpClient, @Inject('BASE_URL') baseUrl: string) {
26 http.get<HealthFacilities[]>(baseUrl + 'HealthFacilities/Get?').subscribe(result => {
27 this.facilities = result;
28 console.log(this.facilities);
29 this.dataSource = new MatTableDataSource<HealthFacilities>(this.facilities);
30 }, error => console.error(error));
31 http.get<HealthcareWorkers[]>(baseUrl + 'HealthcareWorker/Get?').subscribe(result => {
32 this.workers = result;
33 console.log(this.workers);
34 this.dataSourceWorkers = new MatTableDataSource<HealthcareWorkers>(this.workers);
35 }, error => console.error(error));
36 }
37 ngOnInit(): void {
38 }
39
40 ngAfterViewInit(): void {
41 this.dataSource.paginator = this.paginator;
42 this.dataSource.sort = this.sort;
43 this.dataSourceWorkers.paginator = this.paginator;
44 this.dataSourceWorkers.sort = this.sort;
45 }
46
47 applyFilter(filterValue: string) {
48 filterValue = filterValue.trim();
49 filterValue = filterValue.toLowerCase();
50 this.dataSource.filter = filterValue;
51 }
52
53 applyFilterWorkers(filterValue: string) {
54 filterValue = filterValue.trim();
55 filterValue = filterValue.toLowerCase();
56 this.dataSourceWorkers.filter = filterValue;
57 }
58}
Note: See TracBrowser for help on using the repository browser.