Signal Inputs, Outputs, and Model vs. Decorators
CONCEPTS:Signal-based Component APIs
Question Variations
- "How do Signal-based inputs (`input()`) differ from traditional `@Input()` decorators?"
- "What is the `model()` function in Angular, and how does it simplify two-way data binding?"
- "Why are signal-based inputs read-only, and how do you handle derived state from them?"
- "Explain the benefits of using `input.required()` over the traditional `@Input({ required: true })`."
Why This Is Asked
The shift from @Input() and @Output() to input() and output() is a fundamental change in how Angular components are authored. Interviewers want to see if you understand the benefits of the signal-based approach—primarily how inputs being signals simplifies reactive logic (computed, effect) and improves type safety (especially for required inputs). They also want to check your understanding of model() for two-way binding.
Key Concepts
- Read-only Signals: Why
input()returns a signal you cannot mutate. input.required(): Native support for mandatory inputs without hacks.- Two-way binding with
model(): Simplifying the[(value)]pattern. - Native Effect Integration: How inputs as signals work with
effect(). - Type Inference: Better TypeScript support compared to decorators.
Question Variations
- “How do Signal-based inputs (
input()) differ from traditional@Input()decorators?” - “What is the
model()function in Angular, and how does it simplify two-way data binding?” - “Why are signal-based inputs read-only, and how do you handle derived state from them?”
- “Explain the benefits of using
input.required()over the traditional@Input({ required: true }).”