Skip to content

Commit 03a1f04

Browse files
committed
feat: solve problem 8 pure pipe
1 parent e955435 commit 03a1f04

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed
Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
import { 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
})
1113
export class AppComponent {
1214
persons = ['toto', 'jack'];
13-
14-
heavyComputation(name: string, index: number) {
15-
// very heavy computation
16-
return `${name} - ${index}`;
17-
}
1815
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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+
}

0 commit comments

Comments
 (0)