| 
									
										
										
										
											2015-12-23 09:42:57 -08:00
										 |  |  | // #docplaster
 | 
					
						
							|  |  |  | // #docregion
 | 
					
						
							|  |  |  | import { Hero } from './hero'; | 
					
						
							|  |  |  | import { HEROES } from './mock-heroes'; | 
					
						
							|  |  |  | import { Injectable } from 'angular2/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
 | 
					
						
							| 
									
										
										
										
											2016-03-07 19:05:20 +01:00
										 |  |  |   getHero(id: number) { | 
					
						
							| 
									
										
										
										
											2015-12-23 09:42:57 -08:00
										 |  |  |     return Promise.resolve(HEROES).then( | 
					
						
							|  |  |  |       heroes => heroes.filter(hero => hero.id === id)[0] | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   //#enddocregion get-hero
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | // #enddocregion
 |