Angular Academy · Lesson

Required and Transformed Inputs

Mark inputs required and transform values.

Lesson 2 of 413 steps

Required and Transformed Inputs is a free Angular Academy lesson on CoddyKit. This is lesson 2 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the Angular Academy learning path, and your progress syncs across the web and the CoddyKit app. The Angular Academy course includes 4 lessons in total.

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.

Free to start

Learn HTML with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
38
Lessons
144

Frequently Asked Questions

Is the “Required and Transformed Inputs” lesson free?

Yes — any 3 lessons of the Angular Academy learning path, including “Required and Transformed Inputs”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The Angular Academy course includes 4 lessons in total.

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, so you can start here or from the beginning and move at your own pace. This is lesson 2 of 4.

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

  1. Signal Inputs with input()
  2. Required and Transformed Inputs
  3. Outputs with output()
  4. View Queries with viewChild
← Back to Angular Academy