WIP: 6: Get Data from a Server k) Search by name
[examples/angular-tour-of-heroes] / dashboard / dashboard.component.ts
1 import { Component, OnInit } from '@angular/core';
2 import { Hero } from '../hero';
3 import { HeroService } from '../hero.service';
4
5 @Component({
6   selector: 'app-dashboard',
7   templateUrl: './dashboard.component.html',
8   styleUrls: [ './dashboard.component.css' ]
9 })
10 export class DashboardComponent implements OnInit {
11   heroes: Hero[] = [];
12
13   constructor(private heroService: HeroService) { }
14
15   ngOnInit() {
16     this.getHeroes();
17   }
18
19   getHeroes(): void {
20     this.heroService.getHeroes()
21       .subscribe(heroes => this.heroes = heroes.slice(1, 5));
22   }
23 }