2016-03-26 12:18:13 -04:00
|
|
|
// #docregion
|
2016-05-03 14:06:32 +02:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
|
|
|
|
import { Hero } from './hero';
|
|
|
|
import { HeroService } from './hero.service';
|
2016-03-26 12:18:13 -04:00
|
|
|
|
|
|
|
// #docregion service
|
|
|
|
@Injectable()
|
|
|
|
export class HeroCacheService {
|
|
|
|
hero:Hero;
|
2016-05-03 14:06:32 +02:00
|
|
|
constructor(private heroService:HeroService){}
|
2016-03-26 12:18:13 -04:00
|
|
|
|
|
|
|
fetchCachedHero(id:number){
|
|
|
|
if (!this.hero) {
|
2016-05-03 14:06:32 +02:00
|
|
|
this.hero = this.heroService.getHeroById(id);
|
2016-03-26 12:18:13 -04:00
|
|
|
}
|
|
|
|
return this.hero
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// #enddocregion service
|