mirror of
https://github.com/Raghu-Ch/angular-challenges.git
synced 2026-02-11 05:13:02 -05:00
feat(doc): move pipe intermediate
This commit is contained in:
34
apps/angular/pipe-intermediate/src/app/app.component.ts
Normal file
34
apps/angular/pipe-intermediate/src/app/app.component.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { NgFor } from '@angular/common';
|
||||
import { Component } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
standalone: true,
|
||||
imports: [NgFor],
|
||||
selector: 'app-root',
|
||||
template: `
|
||||
<div *ngFor="let person of persons; let index = index; let isFirst = first">
|
||||
{{ showName(person.name, index) }}
|
||||
{{ isAllowed(person.age, isFirst) }}
|
||||
</div>
|
||||
`,
|
||||
})
|
||||
export class AppComponent {
|
||||
persons = [
|
||||
{ name: 'Toto', age: 10 },
|
||||
{ name: 'Jack', age: 15 },
|
||||
{ name: 'John', age: 30 },
|
||||
];
|
||||
|
||||
showName(name: string, index: number) {
|
||||
// very heavy computation
|
||||
return `${name} - ${index}`;
|
||||
}
|
||||
|
||||
isAllowed(age: number, isFirst: boolean) {
|
||||
if (isFirst) {
|
||||
return 'always allowed';
|
||||
} else {
|
||||
return age > 25 ? 'allowed' : 'declined';
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user