File tree Expand file tree Collapse file tree 2 files changed +15
-7
lines changed
apps/angular/8-pure-pipe/src/app Expand file tree Collapse file tree 2 files changed +15
-7
lines changed Original file line number Diff line number Diff line change 11import { Component } from '@angular/core' ;
2+ import { IndexPipe } from './index.pipe' ;
23
34@Component ( {
45 selector : 'app-root' ,
56 template : `
6- @for (person of persons; track person) {
7- {{ heavyComputation( person, $index) }}
7+ @for (person of persons; track person; let i = $index ) {
8+ <div> {{ person | indexer: i }}</div>
89 }
910 ` ,
11+ imports : [ IndexPipe ] ,
1012} )
1113export class AppComponent {
1214 persons = [ 'toto' , 'jack' ] ;
13-
14- heavyComputation ( name : string , index : number ) {
15- // very heavy computation
16- return `${ name } - ${ index } ` ;
17- }
1815}
Original file line number Diff line number Diff line change 1+ import { Pipe , PipeTransform } from '@angular/core' ;
2+
3+ @Pipe ( {
4+ pure : true ,
5+ name : 'indexer' ,
6+ } )
7+ export class IndexPipe implements PipeTransform {
8+ transform ( value : string , index : number ) {
9+ return `${ value } - ${ index } ` ;
10+ }
11+ }
You can’t perform that action at this time.
0 commit comments