Files
beertracker/dashboard.component.ts

29 lines
680 B
TypeScript

import { Component, OnInit } from '@angular/core';
import { Beer } from './beer';
import { BeerService } from './beer.service';
@Component({
moduleId: module.id,
selector: 'my-dashboard',
templateUrl: './dashboard.component.html'
})
export class DashboardComponent implements OnInit {
beers: Beer[] = [];
beerTypes: string[] = ["Heineken", "Carlsberg", "Westmalle", "Bavaria", "Bud"];
beerType: string = "Heineken";
constructor(private beerService: BeerService) { }
ngOnInit(): void {
this.beerType = this.beerTypes[ Math.floor(Math.random() * 5)];
this.beerService
.search(this.beerType)
.subscribe(beers => this.beers = beers);
}
}