Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions apps/angular/8-pure-pipe/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
// app.component.ts
import { ChangeDetectionStrategy, Component } from '@angular/core';

import { HeavyComputationPipe } from './heavy-computation.pipe';
@Component({
selector: 'app-root',
changeDetection: ChangeDetectionStrategy.Eager,
standalone: true,
imports: [HeavyComputationPipe],
changeDetection: ChangeDetectionStrategy.Default,
template: `
@for (person of persons; track person) {
{{ heavyComputation(person, $index) }}
{{ person | heavyComputation: $index }}
}
`,
})
export class AppComponent {
persons = ['toto', 'jack'];

heavyComputation(name: string, index: number) {
// very heavy computation
return `${name} - ${index}`;
}
// heavyComputation(name: string, index: number) {
// // very heavy computation
// return `${name} - ${index}`;
// }
}
13 changes: 13 additions & 0 deletions apps/angular/8-pure-pipe/src/app/heavy-computation.pipe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// heavy-computation.pipe.ts
import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
name: 'heavyComputation',
standalone: true,
})
export class HeavyComputationPipe implements PipeTransform {
transform(name: string, index: number): string {
console.log('触发了复杂计算:', name);
return `${name} - ${index}`;
}
}
1 change: 1 addition & 0 deletions apps/angular/8-pure-pipe/src/index.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!-- index.html -->
<!doctype html>
<html lang="en">
<head>
Expand Down
1 change: 1 addition & 0 deletions apps/angular/8-pure-pipe/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// main.ts
import { provideZoneChangeDetection } from '@angular/core';
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app/app.component';
Expand Down
Loading