2015-12-23 09:42:57 -08:00
|
|
|
// #docplaster
|
|
|
|
// #docregion
|
|
|
|
import { Hero } from './hero';
|
|
|
|
import { HEROES } from './mock-heroes';
|
2016-04-27 11:28:22 -07:00
|
|
|
import { Injectable } from '@angular/core';
|
2015-12-23 09:42:57 -08:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class HeroService {
|
|
|
|
getHeroes() {
|
|
|
|
return Promise.resolve(HEROES);
|
|
|
|
}
|
|
|
|
|
|
|
|
// See the "Take it slow" appendix
|
|
|
|
getHeroesSlowly() {
|
|
|
|
return new Promise<Hero[]>(resolve =>
|
2016-06-08 01:06:25 +02:00
|
|
|
setTimeout(() => resolve(HEROES), 2000) // 2 seconds
|
2015-12-23 09:42:57 -08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-06-08 01:06:25 +02:00
|
|
|
// #docregion get-hero
|
2016-03-07 19:05:20 +01:00
|
|
|
getHero(id: number) {
|
2016-05-29 22:09:06 +01:00
|
|
|
return this.getHeroes()
|
2016-07-02 16:13:32 -07:00
|
|
|
.then(heroes => heroes.find(hero => hero.id === id));
|
2015-12-23 09:42:57 -08:00
|
|
|
}
|
2016-06-08 01:06:25 +02:00
|
|
|
// #enddocregion get-hero
|
2015-12-23 09:42:57 -08:00
|
|
|
}
|