Angular Tutorial 0/55 lessons ~6 min read Lesson 39

    Angular Signal Inputs

    Signal inputs replace many @Input() decorator patterns with input() and input.required().

    Course progress0%
    Focus
    7 guided sections
    Practice signal
    Examples included
    Career prep
    Interview Q&A included

    Introduction

    Signal inputs replace many @Input() decorator patterns with input() and input.required(). Inputs are signals: templates and computed values read them with (), and change detection stays fine-grained.

    Purpose of this lesson

    You will declare required and optional signal inputs, transform values, and bind them from a parent.

    Understanding the topic

    API shape:

    • title = input<string>() — optional input, type InputSignal<string | undefined>.
    • id = input.required<string>() — required; missing bindings fail at compile/check time.
    • input(..., { alias, transform }) — rename the public attribute or coerce strings from templates.
    • Read with title() in TypeScript and templates — never assign to an input signal.

    Informative example

    Lesson meta with a transform:

    typescript
    import { Component, computed, input, numberAttribute } from "@angular/core";
    @Component({
    selector: "tlp-lesson-meta",
    template: `
    <p>{{ title() }} · {{ minutes() }} min</p>
    @if (isLong()) {
    <p>Long-form lesson</p>
    }
    `,
    })
    export class LessonMetaComponent {
    title = input.required<string>();
    minutes = input(15, { transform: numberAttribute });
    isLong = computed(() => this.minutes() >= 30);
    }
    // Parent template:
    // <tlp-lesson-meta title="Signals" minutes="35" />

    Best practices

    • Prefer input.required for values the component cannot sensibly default.
    • Derive UI state with computed from inputs instead of ngOnChanges.
    • Use transform for attribute coercion (booleans, numbers) from HTML strings.

    Common mistakes

    • Writing this.title.set(...) — inputs are read-only from inside the component.
    • Mixing decorator @Input and signal inputs on the same field.

    Advanced interview questions

    Interview Prep

    Practice concise answers, then expand each card for the explanation.

    1 questions
    1IntermediateQuestionHow do signal inputs differ from @Input()?+

    Answer

    Signal inputs are InputSignal values you read with (). They integrate with computed/effect and reduce ngOnChanges boilerplate. @Input still works, but new code should prefer input()/input.required().
    Ready to mark this lesson complete?Track your journey across the entire course.