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

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

Prepared and improved components for data flows

  • Property mode set to 100644
File size: 2.2 KB
Line 
1import { Component, OnInit, ViewChild, Inject } from '@angular/core';
2import { HttpClient } from '@angular/common/http';
3import { Medicine } from '../models/Medicine';
4import { Pharmacy } from '../models/Pharmacy';
5import { MatTableDataSource } from '@angular/material/table';
6import { MatPaginator } from '@angular/material/paginator';
7import { MatSort } from '@angular/material/sort';
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 medicines: Medicine[];
16 public pharmacies: Pharmacy[];
17 displayedColumns = ['Име','Јачина','Форма', 'Начин на издавање', 'Производител', 'Цена', 'Пакување'];
18 displayedColumnsPharmacies = ['Име','Локација','Адреса', 'Работи 27/7?'];
19 dataSource = new MatTableDataSource<Medicine>();
20 dataSourcePharmacies = new MatTableDataSource<Pharmacy>();
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<Medicine[]>(baseUrl + 'Medicine/Get?').subscribe(result => {
27 this.medicines = result;
28 console.log(this.medicines);
29 this.dataSource = new MatTableDataSource<Medicine>(this.medicines);
30 }, error => console.error(error));
31 http.get<Pharmacy[]>(baseUrl + 'Pharmacy/Get?').subscribe(result => {
32 this.pharmacies = result;
33 console.log(this.pharmacies);
34 this.dataSourcePharmacies = new MatTableDataSource<Pharmacy>(this.pharmacies);
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.dataSourcePharmacies.paginator = this.paginator;
44 this.dataSourcePharmacies.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 applyFilterPharmacies(filterValue: string) {
54 filterValue = filterValue.trim();
55 filterValue = filterValue.toLowerCase();
56 this.dataSourcePharmacies.filter = filterValue;
57 }
58}
Note: See TracBrowser for help on using the repository browser.