27 lines
600 B
TypeScript
27 lines
600 B
TypeScript
// #docplaster
|
|
// #docregion
|
|
import { Hero } from './hero';
|
|
import { HEROES } from './mock-heroes';
|
|
import { Injectable } from '@angular/core';
|
|
|
|
@Injectable()
|
|
export class HeroService {
|
|
getHeroes() {
|
|
return Promise.resolve(HEROES);
|
|
}
|
|
|
|
// See the "Take it slow" appendix
|
|
getHeroesSlowly() {
|
|
return new Promise<Hero[]>(resolve =>
|
|
setTimeout(() => resolve(HEROES), 2000) // 2 seconds
|
|
);
|
|
}
|
|
|
|
// #docregion get-hero
|
|
getHero(id: number) {
|
|
return this.getHeroes()
|
|
.then(heroes => heroes.filter(hero => hero.id === id)[0]);
|
|
}
|
|
// #enddocregion get-hero
|
|
}
|