| 
									
										
										
										
											2016-03-24 19:30:26 +00: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'; | 
					
						
							| 
									
										
										
										
											2016-03-17 14:07:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | @Injectable() | 
					
						
							|  |  |  | export class HeroService { | 
					
						
							| 
									
										
										
										
											2016-03-24 19:30:26 +00:00
										 |  |  |   getHeroes() { | 
					
						
							|  |  |  |     return Promise.resolve(HEROES); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-03-17 14:07:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-24 19:30:26 +00:00
										 |  |  |   // 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
 | 
					
						
							| 
									
										
										
										
											2016-03-24 19:30:26 +00:00
										 |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-03-17 14:07:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 01:06:25 +02:00
										 |  |  |   // #docregion get-hero
 | 
					
						
							| 
									
										
										
										
											2016-03-24 19:30:26 +00:00
										 |  |  |   getHero(id: number) { | 
					
						
							|  |  |  |     return Promise.resolve(HEROES).then( | 
					
						
							|  |  |  |       heroes => heroes.filter(hero => hero.id === id)[0] | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-06-08 01:06:25 +02:00
										 |  |  |   // #enddocregion get-hero
 | 
					
						
							| 
									
										
										
										
											2016-03-17 14:07:54 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2016-06-08 01:06:25 +02:00
										 |  |  | // #enddocregion
 |