angular/aio/content/errors/NG0950.md
Paul Gschwendtner 1df95cd1c1 refactor(core): improve error message and add guide for required inputs (#53808)
Whenever a required input is accessed too early in a
directive/component, the signal input will throw an error.

This is necessary so that we can support required inputs
with intuitive typings that do not include `undefined` for
the short period of time where Angular is creating the component and
then assigning inputs later (Angular currently has no way of setting
inputs as part of the class creation when `new Dir()` happens)

PR Close #53808
2024-01-10 12:21:05 +00:00

703 B

@name Input is required but no value is available yet. @category runtime @shortDescription A required input is accessed before a value is set.

@description A required input was accessed but no value was bound.

This can happen when a required input is accessed too early in your directive or component. This is commonly happening when the input is read as part of class construction.

Inputs are guaranteed to be available in the ngOnInit lifecycle hook and afterwards.

Fixing the error

Access the required input in reactive contexts. For example, in the template itself, inside a computed, or inside an effect.

Alternatively, access the input inside the ngOnInit lifecycle hook, or later.