angular-docs-cn/public/docs/_examples/cb-dependency-injection/ts/app/hero.service.ts

23 lines
560 B
TypeScript
Raw Normal View History

2016-03-26 12:18:13 -04:00
// #docregion
import { Injectable } from '@angular/core';
import { Hero } from './hero';
2016-03-26 12:18:13 -04:00
@Injectable()
export class HeroService {
// TODO move to database
private heroes: Array<Hero> = [
new Hero(1, 'RubberMan', 'Hero of many talents', '123-456-7899'),
new Hero(2, 'Magma', 'Hero of all trades', '555-555-5555'),
new Hero(3, 'Mr. Nice', 'The name says it all', '111-222-3333')
2016-03-26 12:18:13 -04:00
];
getHeroById(id: number): Hero {
return this.heroes.find(hero => hero.id === id);
2016-03-26 12:18:13 -04:00
}
getAllHeroes(): Array<Hero> {
return this.heroes;
2016-03-26 12:18:13 -04:00
}
2016-05-01 17:04:47 -04:00
}