Note that, for simple values, typescript can infer the type by value, but for complex types, you need to specify the type.
1 2
value = input<number>(0); // value = input(0); // totally ok value = input<string>(''); // value = input(''); // totally ok
required
1
value = input.required<number>(); // required
Input transform
1 2 3 4 5 6 7 8 9
exportclassListItemComponent { id = input.required<string>(); name = input('', {transform: trimString}); // apply transform }
// define transform function, transform function should be statically analyzable and pure function. functiontrimString(value: string | undefined): string { return value?.trim() ?? ''; }
Built-in transform
booleanAttribute - imitates the behavior of standard HTML boolean attributes, where the presence of the attribute indicates a “true” value. However, Angular’s booleanAttribute treats the literal string “false” as the boolean false.
numberAttribute - attempts to parse the given value to a number, producing NaN if parsing fails.
Input alias
1
value = input(0, {alias: 'sliderValue'}); // aliasValue is the alias name