angular-cn/public/docs/_examples/tutorial/ts/app/hero.service.ts

16 lines
317 B
TypeScript

import {Injectable} from '@angular/core';
import {HEROES} from './mock-heroes';
@Injectable()
export class HeroService {
getHeroes() {
return Promise.resolve(HEROES);
}
getHero(id: number) {
return Promise.resolve(HEROES).then(
heroes => heroes.filter(hero => hero.id === id)[0]
);
}
}