Project

General

Profile

1 57592 stefania.m
import { Component, DoCheck, OnInit, ViewEncapsulation } from '@angular/core';
2
import { DataService } from '../../services/data.service';
3 57732 stefania.m
import { CountryOverview, OverviewData } from '../../domain/overview-data';
4 57592 stefania.m
5
@Component({
6
  selector: 'app-home',
7
  templateUrl: './home.component.html',
8
  // styleUrls: ['./top-menu.component.css'],
9
  encapsulation: ViewEncapsulation.None
10
})
11
12
export class HomeComponent implements OnInit {
13
14
  overviewData: OverviewData;
15
16
  countrySelectedName: string = null;
17 57732 stefania.m
  countrySelectedOverview: CountryOverview = null;
18 57592 stefania.m
19
  constructor(private dataService: DataService) { }
20
21
  ngOnInit(): void {
22
    this.dataService.getOverviewData().subscribe(
23
      overviewData => {
24
        this.overviewData = overviewData;
25
      },
26
      error => {
27
        console.log(error);
28
      }
29
    );
30
  }
31
32
  countrySelected(countryName: string) {
33 57732 stefania.m
    // console.log('Country selected: ', countryName);
34 57592 stefania.m
    this.countrySelectedName = countryName;
35 57732 stefania.m
    this.countrySelectedOverview = this.overviewData.countries.filter(x => x.country === this.countrySelectedName)[0];
36
    // console.log('Country selected overview: ', this.countrySelectedOverview);
37 57592 stefania.m
  }
38
39
  deselectCountry() {
40
    this.countrySelectedName = null;
41 57732 stefania.m
    this.countrySelectedOverview = null;
42 57592 stefania.m
  }
43
}