Skip to content

Commit e561325

Browse files
committed
refactor: use numberAttribute
1 parent 964b52a commit e561325

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

apps/signal/43-signal-input/src/app/user.component.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
Component,
55
computed,
66
input,
7+
numberAttribute,
78
} from '@angular/core';
89

910
type Category = 'Youth' | 'Junior' | 'Open' | 'Senior';
@@ -28,11 +29,8 @@ const ageToCategory = (age: number): Category => {
2829
export class UserComponent {
2930
name = input.required<string>();
3031
lastName = input<string>();
31-
age = input(0, {
32-
transform: (value: number | string) =>
33-
typeof value === 'string' ? Number(value) : value,
34-
});
32+
age = input(0, { transform: numberAttribute });
3533

3634
fullName = computed(() => `${this.name()} ${this.lastName() ?? ''}`);
37-
category = computed<Category>(() => ageToCategory(this.age() ?? 0));
35+
category = computed<Category>(() => ageToCategory(this.age()));
3836
}

0 commit comments

Comments
 (0)