angular-docs-cn/public/docs/_examples/toh-4/ts/app/hero.service.ts

28 lines
692 B
TypeScript
Raw Normal View History

// #docplaster
// #docregion
// #docregion just-get-heroes
import { Injectable } from '@angular/core';
import { Hero } from './hero';
import { HEROES } from './mock-heroes';
@Injectable()
export class HeroService {
// #docregion get-heroes
getHeroes(): Promise<Hero[]> {
return Promise.resolve(HEROES);
}
2016-06-09 15:18:01 -04:00
// #enddocregion get-heroes, just-get-heroes
// #enddocregion
// See the "Take it slow" appendix
// #docregion get-heroes-slowly
getHeroesSlowly(): Promise<Hero[]> {
return new Promise<Hero[]>(resolve =>
setTimeout(() => resolve(HEROES), 2000) // 2 seconds
);
}
// #enddocregion get-heroes-slowly
2016-06-09 15:18:01 -04:00
// #docregion
// #docregion just-get-heroes
}