Required and Transformed Inputs
Mark inputs required and transform values.
Required and Transformed Inputs is a free Angular Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Angular Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Beyond Basic Inputs
Signal inputs support two powerful features: marking an input as required and transforming incoming values before they are stored.
Required Inputs
Use input.required() when the parent must always provide a value. There is no default.
import { input } from "@angular/core";
export class UserComponent {
userId = input.required<string>();
}Why Required Matters
If a required input is not bound, Angular reports an error, catching mistakes early instead of letting an undefined value slip through.
<!-- error: userId is required -->
<app-user></app-user>
<!-- correct -->
<app-user [userId]="id"></app-user>Required Inputs Are Non-Null
Because a required input must be provided, its type is never undefined, so you can read it safely without null checks.
userId = input.required<string>();
load() {
return this.api.get(this.userId()); // always a string
}Transforming Inputs
The transform option runs a function on the incoming value before it is stored, useful for coercion.
import { input } from "@angular/core";
export class ToggleComponent {
disabled = input(false, { transform: (v: unknown) => !!v });
}Boolean Coercion
Angular ships booleanAttribute to coerce attribute-style values into real booleans, handy for presence-style attributes.
import { input, booleanAttribute } from "@angular/core";
disabled = input(false, { transform: booleanAttribute });
<!-- both work -->
<app-btn disabled></app-btn>
<app-btn [disabled]="true"></app-btn>Number Coercion
Similarly, numberAttribute converts a string attribute into a number.
import { input, numberAttribute } from "@angular/core";
count = input(0, { transform: numberAttribute });
<!-- string "5" becomes number 5 -->
<app-counter count="5"></app-counter>Custom Transform Functions
You can write any transform to normalize values, such as trimming strings.
label = input("", {
transform: (v: string) => v.trim()
});Transform Input vs Output Types
A transform can accept one type and store another. The accepted type is what parents bind; the stored type is what you read.
// accepts string | number, stores number
size = input(0, {
transform: (v: string | number) => Number(v)
});Required and Transform Together
You can combine required with a transform by passing the options object to input.required().
value = input.required({
transform: numberAttribute
});When to Use Each
Use required to enforce a mandatory binding and transforms to coerce or normalize incoming data, keeping your component logic clean and consistent.
Quick Check
Test your understanding of required and transformed inputs.
Recap
Use input.required() for mandatory inputs (non-nullable, no default) and the transform option, including booleanAttribute and numberAttribute, to coerce values. Both can be combined.
Frequently asked questions
Is the “Required and Transformed Inputs” lesson free?
Yes — the full text of “Required and Transformed Inputs” is free to read here on the web, and the Angular Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Angular Academy course, upgrade to CoddyKit PRO.
What will I learn in “Required and Transformed Inputs”?
Mark inputs required and transform values. You practise Angular Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Angular Academy?
No prior experience is required. Angular Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Required and Transformed Inputs” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Angular Academy lesson?
Yes. Every Angular Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Signal Inputs with input()
- Required and Transformed Inputs
- Outputs with output()
- View Queries with viewChild