| 
									
										
										
										
											2016-05-03 14:06:32 +02:00
										 |  |  | import { Injectable } from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import { Hero } from './hero'; | 
					
						
							|  |  |  | import { BackendService } from './backend.service'; | 
					
						
							|  |  |  | import { Logger } from './logger.service'; | 
					
						
							| 
									
										
										
										
											2015-11-28 20:43:09 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | @Injectable() | 
					
						
							| 
									
										
										
										
											2015-12-17 13:49:33 -08:00
										 |  |  | // #docregion class
 | 
					
						
							| 
									
										
										
										
											2015-11-28 20:43:09 -08:00
										 |  |  | export class HeroService { | 
					
						
							| 
									
										
										
										
											2016-06-13 00:41:33 +02:00
										 |  |  |   private heroes: Hero[] = []; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-17 13:49:33 -08:00
										 |  |  |   constructor( | 
					
						
							| 
									
										
										
										
											2016-05-03 14:06:32 +02:00
										 |  |  |     private backend: BackendService, | 
					
						
							|  |  |  |     private logger: Logger) { } | 
					
						
							| 
									
										
										
										
											2015-12-17 13:49:33 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-28 20:43:09 -08:00
										 |  |  |   getHeroes() { | 
					
						
							| 
									
										
										
										
											2016-05-03 14:06:32 +02:00
										 |  |  |     this.backend.getAll(Hero).then( (heroes: Hero[]) => { | 
					
						
							|  |  |  |       this.logger.log(`Fetched ${heroes.length} heroes.`); | 
					
						
							|  |  |  |       this.heroes.push(...heroes); // fill cache
 | 
					
						
							| 
									
										
										
										
											2015-12-17 13:49:33 -08:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2016-05-03 14:06:32 +02:00
										 |  |  |     return this.heroes; | 
					
						
							| 
									
										
										
										
											2015-11-28 20:43:09 -08:00
										 |  |  |   } | 
					
						
							|  |  |  | } |