2015-12-16 21:47:02 -05:00
|
|
|
// #docplaster
|
|
|
|
// #docregion
|
2015-12-01 06:15:14 -05:00
|
|
|
// #docregion just-get-heroes
|
2016-05-03 08:06:32 -04:00
|
|
|
import { Injectable } from '@angular/core';
|
2016-03-15 08:24:50 -04:00
|
|
|
|
2016-05-03 08:06:32 -04:00
|
|
|
import { Hero } from './hero';
|
|
|
|
import { HEROES } from './mock-heroes';
|
2015-12-16 21:47:02 -05:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class HeroService {
|
2016-05-13 16:32:54 -04:00
|
|
|
// #docregion get-heroes
|
2016-07-27 09:00:59 -04:00
|
|
|
getHeroes(): Promise<Hero[]> {
|
2015-12-16 21:47:02 -05:00
|
|
|
return Promise.resolve(HEROES);
|
|
|
|
}
|
2016-06-09 15:18:01 -04:00
|
|
|
// #enddocregion get-heroes, just-get-heroes
|
|
|
|
// #enddocregion
|
2015-12-16 21:47:02 -05:00
|
|
|
// See the "Take it slow" appendix
|
2016-05-13 16:32:54 -04:00
|
|
|
// #docregion get-heroes-slowly
|
2016-07-27 09:00:59 -04:00
|
|
|
getHeroesSlowly(): Promise<Hero[]> {
|
2015-12-22 13:25:30 -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-16 21:47:02 -05:00
|
|
|
}
|
2016-05-13 16:32:54 -04:00
|
|
|
// #enddocregion get-heroes-slowly
|
2016-06-09 15:18:01 -04:00
|
|
|
// #docregion
|
2015-12-01 06:15:14 -05:00
|
|
|
// #docregion just-get-heroes
|
2015-12-16 21:47:02 -05:00
|
|
|
}
|