2015-12-23 12:42:57 -05:00
|
|
|
// #docplaster
|
|
|
|
// #docregion
|
|
|
|
import { Hero } from './hero';
|
|
|
|
import { HEROES } from './mock-heroes';
|
2016-04-27 14:28:22 -04:00
|
|
|
import { Injectable } from '@angular/core';
|
2015-12-23 12:42:57 -05:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class HeroService {
|
2016-07-27 09:00:59 -04:00
|
|
|
getHeroes(): Promise<Hero[]> {
|
2015-12-23 12:42:57 -05:00
|
|
|
return Promise.resolve(HEROES);
|
|
|
|
}
|
|
|
|
|
2016-07-27 09:00:59 -04:00
|
|
|
getHeroesSlowly(): Promise<Hero[]> {
|
2015-12-23 12:42:57 -05:00
|
|
|
return new Promise<Hero[]>(resolve =>
|
2016-08-26 17:39:57 -04:00
|
|
|
setTimeout(resolve, 2000)) // delay 2 seconds
|
|
|
|
.then(() => this.getHeroes());
|
2015-12-23 12:42:57 -05:00
|
|
|
}
|
|
|
|
|
2016-08-17 16:31:40 -04:00
|
|
|
// #docregion getHero
|
2016-07-27 09:00:59 -04:00
|
|
|
getHero(id: number): Promise<Hero> {
|
2016-05-29 17:09:06 -04:00
|
|
|
return this.getHeroes()
|
2016-07-02 19:13:32 -04:00
|
|
|
.then(heroes => heroes.find(hero => hero.id === id));
|
2015-12-23 12:42:57 -05:00
|
|
|
}
|
2016-08-17 16:31:40 -04:00
|
|
|
// #enddocregion getHero
|
2015-12-23 12:42:57 -05:00
|
|
|
}
|