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