diff --git a/apps/angular/8-pure-pipe/src/app/app.component.ts b/apps/angular/8-pure-pipe/src/app/app.component.ts index 930fe1313..b2916aea2 100644 --- a/apps/angular/8-pure-pipe/src/app/app.component.ts +++ b/apps/angular/8-pure-pipe/src/app/app.component.ts @@ -1,18 +1,15 @@ import { Component } from '@angular/core'; +import { IndexPipe } from './index.pipe'; @Component({ selector: 'app-root', template: ` - @for (person of persons; track person) { - {{ heavyComputation(person, $index) }} + @for (person of persons; track person; let i = $index) { +
{{ person | indexer: i }}
} `, + imports: [IndexPipe], }) export class AppComponent { persons = ['toto', 'jack']; - - heavyComputation(name: string, index: number) { - // very heavy computation - return `${name} - ${index}`; - } } diff --git a/apps/angular/8-pure-pipe/src/app/index.pipe.ts b/apps/angular/8-pure-pipe/src/app/index.pipe.ts new file mode 100644 index 000000000..e4d66cb3c --- /dev/null +++ b/apps/angular/8-pure-pipe/src/app/index.pipe.ts @@ -0,0 +1,11 @@ +import { Pipe, PipeTransform } from '@angular/core'; + +@Pipe({ + pure: true, + name: 'indexer', +}) +export class IndexPipe implements PipeTransform { + transform(value: string, index: number) { + return `${value} - ${index}`; + } +}