angular-cn/public/docs/_examples/cb-dependency-injection/ts/app/runners-up.ts

27 lines
731 B
TypeScript

// #docplaster
// #docregion
import { OpaqueToken } from '@angular/core';
import { Hero } from './hero';
import { HeroService } from './hero.service';
// #docregion runners-up
export const RUNNERS_UP = new OpaqueToken('RunnersUp');
// #docregion runners-up
// #docregion factory-synopsis
export function runnersUpFactory(take: number) {
return (winner: Hero, heroService: HeroService): string => {
/* ... */
// #enddocregion factory-synopsis
return heroService
.getAllHeroes()
.filter((hero) => hero.name !== winner.name)
.map(hero => hero.name)
.slice(0, Math.max(0, take))
.join(', ');
// #docregion factory-synopsis
};
};
// #enddocregion factory-synopsis