1 | import { Component, OnInit, ViewChild, Inject } from '@angular/core';
|
---|
2 | import { HttpClient } from '@angular/common/http';
|
---|
3 | import { HealthFacilities } from '../models/HealthFacilities';
|
---|
4 | import { MatTableDataSource } from '@angular/material/table';
|
---|
5 | import { MatPaginator } from '@angular/material/paginator';
|
---|
6 | import { MatSort } from '@angular/material/sort';
|
---|
7 |
|
---|
8 | @Component({
|
---|
9 | selector: 'app-counter-component',
|
---|
10 | templateUrl: './counter.component.html',
|
---|
11 | styleUrls: ['./counter.component.css']
|
---|
12 | })
|
---|
13 | export class CounterComponent implements OnInit {
|
---|
14 | public facilities: HealthFacilities[];
|
---|
15 | displayedColumns = ['Име','Општина','Адреса', 'Тип', 'Е-пошта', 'Телефон'];
|
---|
16 | dataSource = new MatTableDataSource<HealthFacilities>();
|
---|
17 |
|
---|
18 | @ViewChild(MatPaginator, {static: true}) paginator: MatPaginator;
|
---|
19 | @ViewChild(MatSort) sort: MatSort;
|
---|
20 |
|
---|
21 | constructor(http: HttpClient, @Inject('BASE_URL') baseUrl: string) {
|
---|
22 | http.get<HealthFacilities[]>(baseUrl + 'HealthFacilities/Get?').subscribe(result => {
|
---|
23 | this.facilities = result;
|
---|
24 | console.log(this.facilities);
|
---|
25 | this.dataSource = new MatTableDataSource<HealthFacilities>(this.facilities);
|
---|
26 | }, error => console.error(error));
|
---|
27 | }
|
---|
28 | ngOnInit(): void {
|
---|
29 | }
|
---|
30 |
|
---|
31 | ngAfterViewInit(): void {
|
---|
32 | this.dataSource.paginator = this.paginator;
|
---|
33 | this.dataSource.sort = this.sort;
|
---|
34 | }
|
---|
35 |
|
---|
36 | applyFilter(filterValue: string) {
|
---|
37 | filterValue = filterValue.trim();
|
---|
38 | filterValue = filterValue.toLowerCase();
|
---|
39 | this.dataSource.filter = filterValue;
|
---|
40 | }
|
---|
41 | } |
---|