- updates tests - heavy prose revisions - uses HttpClient (with angular-in-memory-web-api) - test HeroService using `HttpClientTestingModule` - scrub away most By.CSS - fake async observable with `asyncData()` - extensive Twain work - different take on retryWhen - remove app barrels (& systemjs.extras) which troubled plunker/systemjs - add dummy export const to hero.ts (plunkr/systemjs fails w/o it) - shrink and re-organize TOC - add marble testing package and tests - demonstrate the "no beforeEach()" test coding style - add section on Http service testing - prepare for stackblitz - confirm works in plunker except excluded marble test - add tests for avoidFile class feature of CodeExampleComponent PR Close #20697
42 lines
987 B
TypeScript
42 lines
987 B
TypeScript
// #docregion
|
|
import { Component, OnInit } from '@angular/core';
|
|
import { Router } from '@angular/router';
|
|
|
|
import { Hero } from '../model/hero';
|
|
import { HeroService } from '../model/hero.service';
|
|
|
|
@Component({
|
|
selector: 'app-dashboard',
|
|
templateUrl: './dashboard.component.html',
|
|
styleUrls: [ './dashboard.component.css' ]
|
|
})
|
|
export class DashboardComponent implements OnInit {
|
|
|
|
heroes: Hero[] = [];
|
|
|
|
// #docregion ctor
|
|
constructor(
|
|
private router: Router,
|
|
private heroService: HeroService) {
|
|
}
|
|
// #enddocregion ctor
|
|
|
|
ngOnInit() {
|
|
this.heroService.getHeroes()
|
|
.subscribe(heroes => this.heroes = heroes.slice(1, 5));
|
|
}
|
|
|
|
// #docregion goto-detail
|
|
gotoDetail(hero: Hero) {
|
|
let url = `/heroes/${hero.id}`;
|
|
this.router.navigateByUrl(url);
|
|
}
|
|
// #enddocregion goto-detail
|
|
|
|
get title() {
|
|
let cnt = this.heroes.length;
|
|
return cnt === 0 ? 'No Heroes' :
|
|
cnt === 1 ? 'Top Hero' : `Top ${cnt} Heroes`;
|
|
}
|
|
}
|