diff --git a/apps/angular/10-utility-wrapper-pipe/src/app/app.component.ts b/apps/angular/10-utility-wrapper-pipe/src/app/app.component.ts
index 9a8156a5f..82be78cd5 100644
--- a/apps/angular/10-utility-wrapper-pipe/src/app/app.component.ts
+++ b/apps/angular/10-utility-wrapper-pipe/src/app/app.component.ts
@@ -1,8 +1,9 @@
import { Component } from '@angular/core';
-import { PersonUtils } from './person.utils';
+import { WrapperUtilsPipe } from './wrapper-utils.pipe';
@Component({
selector: 'app-root',
+ imports: [WrapperUtilsPipe],
template: `
@for (activity of activities; track activity.name) {
{{ activity.name }} :
@@ -12,8 +13,9 @@ import { PersonUtils } from './person.utils';
let index = $index;
let isFirst = $first
) {
- {{ showName(person.name, index) }}
- {{ isAllowed(person.age, isFirst, activity.minimumAge) }}
+ {{ 'showName' | wrappFn: person.name : index }}
+ {{ 'isAllowed' | wrappFn: person.age : isFirst : activity.minimumAge }}
+
}
}
`,
@@ -30,8 +32,4 @@ export class AppComponent {
{ name: 'hiking', minimumAge: 25 },
{ name: 'dancing', minimumAge: 1 },
];
-
- showName = PersonUtils.showName;
-
- isAllowed = PersonUtils.isAllowed;
}
diff --git a/apps/angular/10-utility-wrapper-pipe/src/app/person.utils.ts b/apps/angular/10-utility-wrapper-pipe/src/app/person.utils.ts
index 66451dad4..35e1313d2 100644
--- a/apps/angular/10-utility-wrapper-pipe/src/app/person.utils.ts
+++ b/apps/angular/10-utility-wrapper-pipe/src/app/person.utils.ts
@@ -15,3 +15,16 @@ export const PersonUtils = {
showName,
isAllowed,
};
+
+export type PersonUtils = typeof PersonUtils;
+
+export type PersonUtilsFnKey = {
+ [K in keyof PersonUtils]: PersonUtils[K] extends (...args: any[]) => any
+ ? K
+ : never;
+}[keyof PersonUtils];
+
+export type PersonUtilParams =
+ PersonUtils[K] extends (...args: infer A) => any ? A : never;
+export type PersonUtilReturnType =
+ PersonUtils[K] extends (...args: any[]) => infer R ? R : never;
diff --git a/apps/angular/10-utility-wrapper-pipe/src/app/wrapper-utils.pipe.ts b/apps/angular/10-utility-wrapper-pipe/src/app/wrapper-utils.pipe.ts
new file mode 100644
index 000000000..505f4157f
--- /dev/null
+++ b/apps/angular/10-utility-wrapper-pipe/src/app/wrapper-utils.pipe.ts
@@ -0,0 +1,19 @@
+import { Pipe, PipeTransform } from '@angular/core';
+import {
+ PersonUtilParams,
+ PersonUtilReturnType,
+ PersonUtils,
+ PersonUtilsFnKey,
+} from './person.utils';
+
+@Pipe({
+ name: 'wrappFn',
+})
+export class WrapperUtilsPipe implements PipeTransform {
+ transform(
+ fn: T,
+ ...args: PersonUtilParams
+ ): PersonUtilReturnType {
+ return (PersonUtils[fn] as Function)(...args);
+ }
+}