21 lines
444 B
TypeScript
Raw Normal View History

2016-03-26 12:18:13 -04:00
// #docregion
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;
constructor(private heroService: HeroService) {}
2016-03-26 12:18:13 -04:00
fetchCachedHero(id: number) {
2016-03-26 12:18:13 -04:00
if (!this.hero) {
this.hero = this.heroService.getHeroById(id);
2016-03-26 12:18:13 -04:00
}
return this.hero;
2016-03-26 12:18:13 -04:00
}
}
// #enddocregion service