source: Farmatiko/ClientApp/src/app/home/home.component.ts@ ef1219a

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

Handled REST API calls, searchbars and paginators implemented, overall frontend improvment

  • Property mode set to 100644
File size: 1.5 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';
7
8
9@Component({
10 selector: 'app-home',
11 templateUrl: './home.component.html',
12 styleUrls: ['./home.component.css']
13})
14export 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}
Note: See TracBrowser for help on using the repository browser.