skip to content
Alvin Lucillo

Required input

/ 1 min read

💻 Tech

In Angular, you can make input to the component required, so that when another component’s template references this component, an error something like this will show: Required input 'name' from component UserComponent must be specified. This ensures that if the implementation uses that data, developers won’t accidentally miss it. If you notice, there’s an exclamation mark beside name. This is a Typescript feature that indicates this variable will be initialized. Combining required and ! make the input required while preventing syntax error from showing due to uninitialized variable.

  @Input({required: true}) name!: string;