Question presented to candidate:
"Our codebase is full of @Input() fields with ngOnChanges blocks that recompute things. Since Angular 17.1 there is input(). What actually changes if we switch, and is there anything we lose?"
What a strong answer should cover:
input()returns a read-only signal (InputSignal<T>); the template and class read it by calling it,label().- Derived values become a
computed()instead ofngOnChangesor a setter, and update automatically. - Required inputs (
input.required<T>()) are checked at compile time (NG8008) and have no!hack; reading one too early throws NG0950. - Transforms (
booleanAttribute,numberAttribute) and aliases carry over as options. - The child cannot write an input signal (no
set); for a value the child changes, usemodel(). - Timeline: developer preview in 17.1, stable in v19;
@Inputis still supported (not deprecated in 22.2.3), and a migration schematic exists.
Clarifying questions expected:
- "Do any of these components assign to their own inputs? Those cannot become plain
input()." - "Do tests set inputs by assigning the field? They will need
fixture.componentRef.setInput()."
Code / implementation expected: Yes — the same component written with @Input() and with input(), ideally with a derived value.